Synchronization

QTP and AUT join or handshake at a certain point to match up their speeds for the event to occur in order to accomplish a certain sequence of action.

Speed mismatch, delays, the wait for property to change, change of object, and occurrence of an event causes mismatch in the speed of execution of scripts, and AUT causes synchronization issues, for example, script has to wait until the page is loaded. The default object synchronization is 20 seconds but we can change it by navigating to File | Test Settings | Run | Object synchronization timeout.

Change the Object synchronization timeout from 20 seconds to 2 seconds as shown in the following screenshot:

Synchronization

Now that we have changed the Object synchronization timeout value, we will run the following script:

'Open the Flight Reservation login window and create the script
Dialog("DialogLogin").WinEdit("AgentName").Set "ashish"
Dialog("DialogLogin").WinEdit("AgentPassword").SetSecure "51d84ff2108dc473a416b19e1fed478fab95ca75"
Dialog("DialogLogin").WinButton("WinOK").Click
'The script will fail at this step, the object synchronization is 2 seconds but window takes more time to open; hence script fails
Window("WinFlight").Activate

To achieve synchronization, we introduce some wait scripts that wait for the specified time. Refer to the following code snippet:

Dialog("DialogLogin").Activate
Dialog("DialogLogin").WinEdit("AgentName").Set "ashish"
Dialog("DialogLogin").WinEdit("AgentPassword").SetSecure "51d84ff2108dc473a416b19e1fed478fab95ca75"
Dialog("DialogLogin").WinButton("WinOK").Click
'The script will fail at this step. To avoid this, insert a wait statement
wait 10'Window("WinFlight").Activate

The wait statement tells QTP to wait for a predefined amount of time, for example, 10 seconds. Here, the following situations can arise:

  • The AUT is ready to perform the next step, but the script is still waiting till the specified time
  • The wait time is over and the AUT is still not ready for the next step to be executed

In both of these conditions, static wait is not a good option. Waiting for an appropriate amount of time based on some property or event that has to be completed is called dynamic synchronization.

Dynamic synchronization

Dynamic synchronization allows waiting till the object property is changed or till time out, as shown in the following example:

Window("WinFlight").ActiveX("MaskEdBox").Type "111114"
Window("WinFlight").WinComboBox("FlyFrom:").Select "Frankfurt"
Window("WinFlight").WinComboBox("FlyTo:").Select "Los Angeles"
Window("WinFlight").WinButton("FLIGHT").Click
Window("WinFlight").Dialog("FlightsTable").WinButton("WinOK").Click
Window("WinFlight").WinEdit("Name:").Set "ashish"
Window("WinFlight").WinButton("Insert Order").Click
'Window("WinFlight").WinButton("Button").Click
'When QTP tries to execute the following statement, application will not allow to click on the button since it is waiting for progress bar to reach 100% and display the message Insert Done...
'Here script will fail
'We need  to insert the dynamic synchronization point; this waits until the text changes to Insert Done...
'Window("WinFlight").ActiveX("ThreedPanelControl").WaitProperty "text", "Insert Done...", 10000

The WaitProperty can be inserted using Insert synchronization point or we can manually add the WaitProperty method by typing it.

Apart from using WaitProperty, we can also create synchronization points using the following code:

Set Object = Window("WinFlight").ActiveX("ThreedPanelControl")
Set WinsObject = Window("WinFlight")
'It accepts the object with its property and value. You have to wait along with timeout
Function ManualSyncPoint (Object,propertyname, propertyval,timeout )
   Do 
  If Object.GetROProperty(propertyname)  =propertyval then
'if propertyname and propertyval match, come out of the loop and execute next step
      Exit Do
  else
       wait(1)
end if 
   Loop While (i <= timeout)
End Function
'In the preceding method we have used the static wait; we can implement it without using wait statement as well
Example 2:
Function ManualSyncPoint2(Object ,propertyname, propertyval, timeout )
   sttimer = Timer
'Timer allows to get the number of seconds elapsed since midnight (12:00 AM)
   Do 
   If Object.GetROProperty(propertyname)  = propertyval then
Exit Do
  else
      end if 
        endtimer = Timer
    'The difference between the two timer objects provides the number of seconds we need to determine for timeout
   Loop While ( int (endtimer-sttimer) <= -timeout)
 End Function
'Function that allows to wait till object exists
Function WaitTillExists(Object, timeout )
loadtimer = Timer
 Do
      isObjectExists = Object.Exist
  If isObjectExists = true Then
  Exit Do
    else
  End If
    completetimer = Timer
 Loop While(completetimer-loadtimer  <= timeout)
End Function
'Now we will use these functions in our scripts; refer to the following script
Dialog("DialogLogin").Activate
Dialog("DialogLogin").WinEdit("AgentName").Set "ashish"
Dialog("DialogLogin").WinEdit("Password").SetSecure "51d84ff2108dc473a416b19e1fed478fab95ca75"
Dialog("DialogLogin").WinButton("WinOK").Click
' wait
'Go to the test settings and make object synchronization time to 2 sec
WaitTillExists WinsObject, 10
Window("WinFlight").Activate
Window("WinFlight").ActiveX("MaskEdBox").Type "111114"
Window("WinFlight").WinComboBox("FlyFrom:").Select "Frankfurt"
Window("WinFlight").WinComboBox("FlyTo:").Select "Los Angeles"
Window("WinFlight").WinButton("FLIGHT").Click
Window("WinFlight").Dialog("FlightsTable").WinButton("WinOK").Click
Window("WinFlight").WinEdit("Name:").Set "ashish"
Window("WinFlight").WinButton("Insert Order").Click
Window("WinFlight").WinButton("Button").Click
'When QTP tries to execute the following statement, the application will not allow to click on the button since it is waiting for progress bar to reach 100% and display the message Insert Done...
'Here script will fail
'We need to insert the dynamic synchronization point
Window("WinFlight").ActiveX("ThreedPanelControl").WaitProperty "text", "Insert Done...", 5000

'The preceding statement waits till the text property changes to Insert Done... and waits for upto 10 secs
 If ManualSyncPoint1(Object ,"text","Insert Done…",10)  = true then
   'do nothing
  else 
  ExitTest
  end if
Window("WinFlight").WinButton("Button").Click
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.186.92