Sunteți pe pagina 1din 25

Chapter 5 Synchronization

Objectives
After completing this chapter, you will be able to: Define synchronization. Examine when and where synchronization is most helpful. Add a synchronization step for a specified object.

QuickTest Professional Workflow


1 2 3 4

Prepare
Setup for test automation Document manual test steps Check applications/ environment stability Check that data is valid

Create

Verify & Enhance

Integrate

Create basic test Record user actions Confirm successful playback Use Object Repository

Enhance basic test Add synchronization

Integrate tests

Pass data Build integrated test sets

Insert checkpoints
Data drive the test

Figure 5-1 Synchronization in the Workflow

So far we have created a basic test. We should enhance the test by adding a synchronization point.

What is Synchronization?

Figure 5-2 QuickTest Waits For Insert Done Visual Cue

What is Synchronization?

Synchronization is a step added to a test that instructs QuickTest to wait for the state of a property on a particular object to change before proceeding to the next step in the test. Just like a manual tester will wait for a visual cue to know when the AUT has completed its processing, we instruct QTP to wait for a cue prior to moving on to the next step in the test. A synchronization point allows the test to pause while an application process completes, before moving on to the next step.

Some Visual Cue Examples


A progress bar reaches 100% completion. A status message appears. A button becomes enabled. A window opens and is ready for data entry. A pop-up message appears in response to an operation.

Examine the Application

Figure 5-3 Synchronize on the Progress Bar

Examine the Application

QTP has a global object synchronization timeout. When a step attempts to interact with an object that is not available when the application is still processing, QTP will wait for either the object to become available or for the object synchronization timeout to occur. If one process takes considerably longer than others, the global synchronization timeout may not be long enough for the process to complete. And in this case, the next step might fail. To give these longer processes enough time to complete, we add a synchronization point to extend the time QTP will wait before moving on to the next step.

Examine the Application


Wait times often occur before an object becomes available for the next step. For example, in the Flights application, once the Insert Order button has been clicked, a progress bar must complete before the reservation Order No. will be displayed. The progress bar may require additional time before the test can proceed. If insufficient time is allocated for these special circumstances, the test may fail.

Examine the Application

The error message, Object not enabled appears if QuickTest is running a test and proceeds to the next step before the previous step has fully processed. QTP will wait only as long as it takes for the process to complete, not necessarily the full timeout.

Setting General Standard Checkpoint Options


Checkpoint timeout. Specifies the time interval (in seconds) during which Quick Test attempts to perform the checkpoint successfully. Quick Test continues to perform the checkpoint until it passes or until the timeout occurs. If the checkpoint does not pass before the timeout occurs, the checkpoint fails. For example, suppose it takes some time for an object to achieve an expected state. Increasing the checkpoint timeout value in this case can help ensure that the object has sufficient time to achieve that state, enabling the checkpoint to pass (if the data matches) before the maximum timeout is reached. If you specify a checkpoint timeout other than 0, and the checkpoint fails, the Test Results window displays information on the checkpoint timeout.

Add a Synchronization step while Recording

Figure 5-4 Insert a Synchronization Point

Add a Synchronization step while Recording

Synchronization points instruct QuickTest to pause until an object property achieves a specified value. The easiest way to add a synchronization point is while recording. Always add the synchronization point immediately after the step to be synchronized. From the QTP menu bar, choose INSERT STEPSYNCHRONIZATION POINT. Step timeout values add to the global values.

Object Synchronization
Test run 1 Test run 2

Global Timeout Sync Step Timeout


Script Continues

Maximum Total Timeout

OK

Error

Script Continues

Global Timeout

Sync Step Timeout

Maximum Total Timeout

Figure 5-5 Object Synchronization Timeout

Object Synchronization

When the synchronization timeout is set for a step, this value is added to the global timeout value. QTP has a default timeout between test steps of 20000 milliseconds (20 seconds). May not wait for the full timeout to arrive.

Object Synchronization
For example: Lets say an object has a global timeout of 30 seconds and a synchronized timeout of 30 seconds. If the actual time it takes for QTP to recognize the object is 40 seconds, the test will move to the next step after 40 seconds. This feature applies to environments that do not synchronize automatically. Examples of auto-synchronizing environments: - Web; SAP; TE

Understanding and Using Regular Expressions


Regular expressions enable Quick Test to identify objects and text strings with varying values. You can use regular expressions when: defining the property values of an object in dialog boxes or in programmatic descriptions parameterizing a step creating checkpoints with varying values For example, you can use a regular expression if you want to create a text checkpoint on a date text string, but the displayed date changes according to the current date. If you define the date as a regular expression, the checkpoint checks that the captured text string matches the expected date format, rather than checking the exact date value. A regular expression is a string that specifies a complex search phrase. By using special characters, such as a period (.), asterisk (*), caret (^), and brackets ([ ]), you can define the conditions of a search.

Using Regular Expressions for Property Values


If you expect the value of a property to change in a predictable way during each run session, you can use regular expressions when defining or parameterizing property values, for example, in the Object Repository window, or in programmatic descriptions. For example, your site may include a form in which the user inputs data and clicks the Send button to submit the form. When a required field is not completed, the form is displayed again for the user to complete. When resubmitting the form, the user clicks the Resend button. You can define the value of the buttons name property as a regular expression, so that Quick Test ignores variations in the button name when clicking the button.

Using Regular Expressions in Checkpoints


When creating a standard checkpoint to verify the property values of an object, you can set the expected value of an objects property as a regular expression so that an object with a varying value can be verified. For example, suppose you want to check that every window and dialog box in your application contains the name of your application followed by a hyphen (-) and a descriptive title. You can add a checkpoint to each dialog box object in your test to check that the first part of the title contains the name of your application followed by a hyphen. When creating a text checkpoint to check that a varying text string is displayed on your Web site or application, you can define the text string as a regular expression.

Using Regular Expressions in Checkpoints


For example, when booking a flight in the Mercury Tours sample Web site, the total cost charged to a credit card number should not be less than $300. You define the amount as a regular expression, so that Quick Test will ignore variations in the text string as long as the value is not less than $300. You can apply the same principles to any checkpoint type whose dialog box contains a Configure Value area similar to that described in Configuring Constant and Parameter Values. For example, for table checkpoints you can set cell values as regular expressions, and for XML checkpoints you can set attribute or element values as regular expressions. For more information on specific checkpoint types, see the relevant chapter for the checkpoint type.

Defining Regular Expressions


You can define a regular expression for a constant value, a Data Table parameter value, an Environment parameter value, or a property value in a programmatic description. You can define a regular expression by entering the regular expression syntax for the string in the Value box in the Constant Value Options dialog box or the Parameter Options dialog box. You instruct Quick Test to treat the value as a regular expression by selecting the Regular Expression check box. By default, Quickest treats all characters in a regular expression literally, except for the period (.), hyphen (-), asterisk (*), caret (^), brackets ([ ]), parentheses (()), dollar sign ($), vertical line (|), plus sign (+), question mark (?), and backslash (\). When one of these special characters is preceded by a backslash (\), Quick Test treats it as a literal character.

Review Questions
1.

What is the function of a synchronization point?


To update test data b) To give more time for an object to process before moving onto the nest step c) To set an environment variable for an object
a)

2.

What is the default time QuickTest waits for a step to process?


2 minutes b) 20 seconds c) 2 milliseconds
a)

3.

What operation in the Flight AUT might require synchronization?


Entering the passenger name b) Deleting an order c) Inserting an order d) Selecting the business class
a)

4.

How long will QTP wait if: - synchronization timeout is set to 10 seconds and the global timeout is set to 40 seconds, but the actual time for the object to be recognized is 25 seconds:
10 b) 40 c) 50 d) None of the above
a)

S-ar putea să vă placă și