Thursday, November 27, 2014

Synchronization Points

When AUT takes some time to respond to an action, QTP might execute the next steps for which the application is not yet ready. In this situation QTP might throw an error. Normally we see "Object is disabled" message.

In this case, synchronization points are used to pause the script to execute certain steps in the test.

There are 4 different types of Synchronization points...

First : 

Browser("....").Page("...").WebList("List").Select "Something"

'Wait for page to load
Browser("...").Sync

'Perform next actions in the scripts
Browser("...").Page("...").WebButton("ButtonName").Click

Second:

Browser("....").Page("...").WebList("List").Select "Something"

'Wait for page to load
Wait 2 ' Waits for 2 Seconds

'Perform next actions in the scripts
Browser("...").Page("...").WebButton("ButtonName").Click

Third:

Browser("....").Page("...").WebList("List").Select "Something"

'Wait for max 5 seconds or until the button gets enabled, whichever is lesser
Browser("...").Page("...").WebButton("ButtonName").WaitProperty("Enabled",True,5000)
Browser("...").Page("...").WebButton("ButtonName").Click

Four:

Browser("....").Page("...").WebList("List").Select "Something"

'Wait for max 5 seconds for button to appear/enable
bAppear = Browser("...").Page("...").WebButton("ButtonName").Exist(5)

'Verify the button exist 
If bAppear Then
Browser("...").Page("...").WebButton("ButtonName").Click
Else
'Report the message to QTP Results
End if