Wait() function in QTP

qtp
28,464

Solution 1

The standard way of dealing with this kind of scenarios is to use .Sync method of the Page (or in some cases Browser) objects.

I found it very temperamental and depending on the tested application this function might work perfectly and on the other occasion will not wait long enough.

The problem seems to be related mainly to Web 2.0 applications (AJAX based). Web page connection to the server is usually closed much earlier then asynchronous connection opened by java script.

If there is a visual guide indicating that that page is still loading you could write a loop and check for that object. Once the object disappear you could resume test execution.

To save yourself writing this code in every place where you need to sync you could overwrite QTP native method with your own version with following code:

RegisterUserFunc "Page", "Sync", "SyncToPage"
Function SyncToPage(oPage)
    'Call native function first'
    oPage.Sync

    'Custom sync code'

End Function

Thanks, Maciej

Solution 2

The sync functionality is what you want. You can use it in a variety of ways, such as:

  • For a web page to load.
  • For a button to become enabled or disabled.
  • For client-server communications to finish.

Think about what is happening in the GUI to indicate to you that the operation has completed. This particular object and/or property is what you want to sync on.

http://qtp.blogspot.com/2007/09/qtp-sync-wait-and-synchronization.html

Other options include using the WaitProperty and Exist commands to synchronize the script with the application.

http://www.sqaforums.com/showflat.php?Number=555273

The QTP function reference should help with using these functions and explaining the parameters used. If you are still having issues, post a code segment so we can take a look.

Solution 3

WaitProperty Method is best solution for this scenario.

Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step.

Return Value: A Boolean value. Returns TRUE if the property achieves the value, and FALSE if the timeout is reached before the property achieves the value. A FALSE return value does not indicate a failed step.

Share:
28,464
galstar
Author by

galstar

Updated on January 30, 2020

Comments

  • galstar
    galstar over 4 years

    Can any body suggest me a function which I can use in QTP for following scenario...

    As sometimes page navigation take times due to which our script shows an error. For that we use the wait(time) function, but it is a fixed time for which the QTP control waits. I want to use a function (I have heard about the sync function, but don't know how to use it) so that QTP waits only for the time, time taken in navigation (not more/less then it).