How to add synchronisation points in QTP

There are 4 ways in which we can add synchronisation  points in QTP .

  • Wait statement - This statement will pause the execution for x seconds until object comes up.
  • Waitproperty - This method will wait until property of object takes particular value
  • Exist statement - This statement will wait until object becomes available.
  • sync method - This method is used in web application testing. Used to wait until page loads.
Examples  -

Wait statement
Wait 2   ' wait for 2 seconds
'Wait statement should be used rarely as it suspends the execution of the script for the fixed amount of time.
'Unless you know exact amount of time, you should not use wait statement. This will slow down execution

WaitProperty method
To eliminate the problem associated with wait statement, we can use either waitproperty or exist method.
In  waitproperty and  exist methods, we do not wait for the fixed amount of the time but for only required amount of time.

In case of waitproperty, we wait until particular property value becomes the expected one. We can also specify the time out.

Example -
ActiveX("panel").WaitProperty "text", "Done", 4000

'This code  will wait until text property of panel object becomes Done. Max timeout is 4 seconds. That means the QTP will wait for the maximum time of 4 seconds. If the text property becomes Done in say 2 second then QTP will jump to next statement in the script.

Exist method
To eliminate the problem associated with wait statement, we can also use exist method.
In case of exist method, we wait until particular object becomes available. We can also specify the max time out.

If window("mywin").Exist(5) Then
   'do some operation
    'In This code QTP waits until mywin window object is displayed
Else
    print "mywin window does not exist even after waiting for 5 seconds"  
End If

Sync method
sync method can be used only in case of web application testing. Browser("myb").sync  'This code will wait untill browser page is completely loaded.