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"
    wait 1
    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")
    .ActiveX("MaskEdBox").Type "010112"
    .WinComboBox("Fly From:").Select "London"
    .WinComboBox("Fly To:").Select "Los Angeles"
    .Dialog("Flights Table").WinButton("OK").Click
    .WinEdit("Name:").Set "Abhikansh"
    .WinEdit("Tickets:").SetSelection 0,1
    .WinEdit("Tickets:").Set "2"
    .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.


  1. For syncronisation or wait to loads a page following code can be used..
    Browser("").Page("").Waitproperty "loading" , "completed"

  2. Thanks Ashi for the way you found to load a page.

  3. Advertising is your main tool to have the business ready to go. Actually, everybody is busy in their company marketing over the World Wide Web. Unfortunately, online company is scammed with scammers. On occasion the provider hires you freelance, or occasionally it is a site designer which orders the copy google At an identical time, if you decide on the most suitable company having excellent reviews and reputation, you will enjoy well composed works.

  4. Wow, thank you. I needed to write such code for a college, but I'm really bad at this thing. So I googled until I found your post) Thank you so much. Maybe I won't gate A or B, but at least I can have D and close that stupid course.

  5. Thank you so much! This is the best essay help ever! I will check your other posts.

  6. Very interesting article, I really like what shering comrades on this page.
    Phd Dissertation Writing Services