tags:

views:

59

answers:

3

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).

+1  A: 

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.

Edward Leno
Browser("Home_2").Page("Home").WebEdit("ctl00$uxMNJDefaultContentPlace").Click Browser("Home_2").Page("Home").WebEdit("ctl00$uxMNJDefaultContentPlace").Set username 'Read User name from datasheetBrowser("Home_2").Page("Home").WebEdit("ctl00$uxMNJDefaultContentPlace_2").ClickBrowser("Home_2").Page("Home").WebEdit("ctl00$uxMNJDefaultContentPlace_2").Set Password'Read Password from datasheetBrowser("Home_2").Page("Home").Link("Sign In").ClickNow after sign in it talkes time to redirect the page to another page..but in mean while QTP shows error as it couldn't find the next object.
galstar
So i use wait(10) after signup operation..but some time it takes more then 10 millisec/sec to redirect to another page...this is the issue.and if i increase it to wait(100)...then QTP wait for 100 millisec/sec for next step but sign in operation take only 11 millisec/sec.
galstar
Please read both the above comments...Thanks
galstar
@galstar - After the signin operation, you need something like ...Browser("Home_2").Page("New Page").WaitProperty("name", "Welcome: User 123", 120000)This will wait for up to 120 seconds for an object called 'name' on the 'New Page' to have a value of 'Welcome: User 123'. This will indicate that the login was successful.
Edward Leno
+1  A: 

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

Maciej Zaleski
A: 

The best way to be sure is often to use Exists(timeout) on an object from the new page.

Motti