Ajax has been widely used. When using qtp to test Ajax applications, you often encounter the need to wait for Ajax operations to complete data loading. Relevantcodes.com's "qtp: synchronization for Ajax Applications" article describes how to encapsulate an ajaxutil object to handle these problems in a unified manner:
Http://relevantcodes.com/qtp-synchronization-for-ajax-applications/
The following is an example of using the ajaxutil object:
Systemutil. Run "iexplore.exe", "www.kayak.com"
If not browser ("title: = cheap flights. *"). exist (10) Then exittest
Ajaxutil. objectsync = 30 'check if the added objects exist before we synchronize
Ajaxutil. statussync = 10' wait for a max 10 seconds if there is no status change
'Add objects to collection (its mandatory that you add objects to the class)
Ajaxutil. addobject "mybrowser1", browser ("title: = cheap flights .*")
Ajaxutil. addobject "mytable", browser ("title: = kayak.com search results ")_
. Webtable ("innertext: =. * Of. * roundtrips shown. * |. * forget all. *", "index: = 0 ")
Ajaxutil. addobject "mybrowser2", browser ("title: = kayak.com search results ")
Browser ("title: = cheap flights. *"). webedit ("html id: = destination ")_
. Set "Atlanta, Ga-Hartsfield-Jackson (ATL )"
'Its mandatory that you set a browser for which you will run the test for changes in Elements
Ajaxutil. setbrowser "mybrowser1" 'required step
'Synchronize for changes in objects:
Ajaxutil. syncobjects "webelement"
Browser ("title: = cheap flights. *"). webbutton ("html id: = fdimgbutton"). Click
'You can modify the objectsync and statussync times here for the next operations.
'Example: statussync is increased
Ajaxutil. statussync = 15 'crease the statussync
'Synchronize with the flights table
Ajaxutil. syncwebtable "mytable"
'Test complete-release dictionary
Ajaxutil. destroydict