Pages

Thursday, March 3

Synchronization in QTP - Exist, WaitProperty, Wait

The following example will demonstrate, why synchronization is necessary in many situations.

Option Explicit
Dim orderNo, mypath
mypath = Environment( "ProductDir" ) & "\samples\flight\app\"   ' ProductDir is In-built environment variable
SystemUtil.Run "flight4a.exe", "", mypath,"open"

If Dialog("Login").Exist( 2000 ) Then ' A way of synchronization
    Dialog("Login").WinEdit("Agent Name:").Set "Abhikansh"


    Dialog("Login").WinEdit("Password:").Set "Mercury"
    Dialog("Login").WinButton("OK").Click
    wait 1
Else
    Reporter.ReportEvent micFail, "Synchronization time-out", "Login dialog is not dispalyed"
    ExitTest( "your test name" )  ' it is the name of your QTP Test
End If
If Not Window("Flight Reservation").Exist( 2000 ) Then
    Reporter.ReportEvent micFail, "Synchronization time-out", "Flight Reservation window is not dispalyed"
    ExitTest( "your test name" )  ' it is the name of your QTP Test
End If
With Window("Flight Reservation")
    .WinButton("Button").Click
    .ActiveX("MaskEdBox").Type "010112"
    .WinComboBox("Fly From:").Select "London"
    .WinComboBox("Fly To:").Select "Los Angeles"
    .WinButton("FLIGHT").Click
    .Dialog("Flights Table").WinButton("OK").Click
    .WinEdit("Name:").Set "Abhikansh"
    .WinEdit("Tickets:").SetSelection 0,1
    .WinEdit("Tickets:").Set "2"
    .WinRadioButton("First").Set
    .WinButton("Insert Order").Click
    '.ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 2000 -
    orderNo = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
    MsgBox orderNo, vbInformation, "Order Number"
End With

As there is no sychronization after WinButton("Insert Order").Click , it will display blank message box, which is incorrect!



Think if you are paasing this number to other tests as argument, you might end-up with peculier results.

Now just uncomment this line in above code, and see the difference..
.ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 2000


As we can see in this example, synchronization is required here.
Synchronization points must be used whenever its necessary.
Following are different ways of synchronization :-

1. Exist property 'used above
2. WaitProperty 'used above
3. Wait  'used above


For further information, please post your comments. I'll try to cover all your queries in further posts.