QTP的那些事--QTP测试AJAX时的等待问题(转陈能技老师博客)

本文介绍了一种在QTP中使用AjaxUtil对象解决AJAX应用数据加载等待问题的方法,通过具体示例展示了如何设置和同步AJAX操作,确保测试的准确性和效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AJAX目前已被广泛应用,在使用QTP测试AJAX应用时经常碰到需要等待AJAX操作完成数据加载的问题。relevantcodes.com的《QTP: Synchronization for AJAX Applications》这篇文章介绍了如何封装一个AjaxUtil对象来统一处理这些问题:

http://relevantcodes.com/qtp-synchronization-for-ajax-applications/

下面是一个使用AjaxUtil对象的例子:

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 ' increase the StatusSync

'Synchronize with the flights table

AjaxUtil.SyncWebTable "MyTable"

'Test Complete - release dictionary

AjaxUtil.DestroyDict

转载于:https://www.cnblogs.com/alterhu/archive/2012/02/23/2365178.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值