Tuesday 21 April 2015

What is Synchronization in QTP

QTP-Synchronization:

Sometimes scripts fail when they are run because of the speed mismatch between QTP and the application. QTP is always faster than the application as a result, the application responds to QTP slower than expected and the test fails. Instances where the application responds slower than expected and the test fails. These speed mismatch problems can be handled by synchronising the test. Synchronising the test involves making the QTP wait until the application is ready for performing the next step.

Synchronising the Test

By modifying the default time settings for a test in QTP. QTP provides some setting for the test which makes QTP to wait for the mentioned time in the setting.

  1. Browser Navigation Timeout: This setting makes QTP wait for the web page to load completely for the specified amount of time. By default the maximum wait time specified by QTP is 60 seconds. This setting can further be modified bythe user based on his requirement. This setting is found in File>settings>Web>Browser navigation timeout. This setting is applicable only for web applications.
  2. Object synchronization timeout: This setting makes QTP wait for the specified amount of time for the objects to appear. By default the time setting is 20 seconds which can be modified by the user. these settings can be found in File>Setting>Run>Object synchronization timeout.

Wait/Exist statements
These statements can be inserted to make QTP wait until an object exists.
Wait statement: When a wait statement is encountered, QTP pauses its script execution  for the specified amount of time. Once the specified amount is lapsed, QTP proceeds with the execution of next step.
Syntax: wait(n), where n is the number of seconds.

Exist statement: When a exist statement is inserted it checks if the object exists or not  in the application under test and returns a Boolean value for the same. Based on the return value, appropriated steps can be taken to handle the timing mismatch.You can combine wait and exist statements within a loop to instruct QTP to wait until the objects exists before continuing with the test.

Inserting Synchronization Point

A synchronization point can be inserted which makes QTP pause the test until an object property achieves a specified value. Synchronization point is often referred to as intelligent wait statement. Steps to insert a synchronization point are given below:

  1. Start a recording session. Select Insert>Synchronization Point.
  2. Click the object in your application for which you want to insert a synchronization point.
  3. Select the object for which you want to insert a synchronization point and click OK.

                     
  4. The Add Synchronization Point dialog box opens as shown in figure below:

                     
  5. Enter all the required values in Add Synchronization Point dialog and click OK. A WaitProperty step is added to the Test.

What is Synchronization?

Synchronization point is the time interface between Tool and Application under test. Synchronization point is a feature to specify delay time between one step and another of the test script.
For Example, clicking on a link may load the page is 1 second, sometimes 5 seconds or even it might take 10 seconds to load it completely. It depends on various factors such as the application server response time, network bandwidth , client system capabilities etc.
If the time is varying then the script will fail unless the tester handles these time differences intelligently.

Ways to Insert Sync Point:






Let us say we need to insert a sync point beween clicking on "numbers" link and clicking on "simple Interest" calculator of in "http://easycalculation.com/". We will now take a look at all the 5 ways to insert sync point for the above scenario.

Method 1: WaitProperty

WaitProperty is a method that takes the property name, Value and Timeout value as input to perform the sync. It is a dynamic wait and hence this option is encouraged.

' Method 1 - WaitProperty with 25 seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
 
obj.Link("Simple Interest").WaitProperty "text", "Simple Interest",25000
obj.Link("Simple Interest").Click

Method 2: Exist

Exist is a method that takes the Timeout value as input to perform the sync. Again it is a dynamic wait and hence this option is encouraged.

' Method 2 : Exist Timeout - 30 Seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
 
If obj.Link("Simple Interest").Exist(30) Then
        obj.Link("Simple Interest").Click
Else
        Print "Link NOT Available"
End IF

Method 3: Wait

Wait is a hardcoded sync point which waits independent of the event happened or NOT. Hence usage of Wait is discouraged and can be used for shorter wait time such as 1 or 2 seconds.

' Method 3 : Wait Timeout - 30 Seconds
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
wait(30)
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").Click

Method 4: Sync Method

Sync Method can be used only for web applications where there is always a lag between page loads.

' Method 4 : 
Dim obj
Set obj = Browser("Math Calculator").Page("Math Calculator")
obj.Link("Numbers").Click
 
Browser("Math Calculator").Sync
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").Click

Method 5 : Inserting QTP Inbuilt Synchronization points:

Step 1 : Get into Recording Mode. This Option Would be Disabled if the user is NOT in Recording Mode.
Step 2 : Goto "Design" -> "Synchronization Point" .
Step 3 : We need to Select the object which we want to be the Sync Point. After Selecting the object, object window opens as shown below:

Step 4 : Click Ok, the "Add Synchronization Window" Opens up. Select the Property, Value and Time out value and click ok as shown below:

Step 5 : The Script would be generated as shown below which is the same as that of the WaitProperty(Method 1) that we had already discussed:

Browser("Math Calculator").Page("Math Calculator").Link("Numbers").Click
Browser("Math Calculator").Page("Math Calculator").Link("Simple Interest").WaitProperty "text", "Simple Interest", 10000

Default Synchronization:

When user hasn't used any of the above sync methods, still QTP has inbuild Object synchronization timeout which can be adjusted by the user.
Navigate to "File" >> "Settings" >> Run Tab >> Object Synchronization Time out as shown below.

 

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.