QTP设置时延的方法
来源:互联网 发布:别墅网络布线方案 编辑:程序博客网 时间:2024/06/13 17:16
1、QTP统一的每个脚本步骤之间设置延时
运行QTP脚本过程中经常出现,QTP自动单击某个按钮,软件还未给出响应,或者响应需要一段时间,QTP继续自动单击其他按钮,这样有可能导致逻辑出错或弹出识别不到对象等问题。此时,就需要设置每个步骤之间的延时时间,具体操作:打开QTP——tools——options——run——run mode 设置时延。
2、有时统一延长每个脚本步骤之间的时间,运行效率没那么快,只想要在某个响应时间较长的某个步骤延长时间,可以有如下方法:
1)Sync方法;
2)WaitProperty方法;
3)Wait方法;
4)Exist方法;
1)Sync
只有browse和page对象具有Sync方法,其它的对象都不具有该方法,那么browse.sync和page.sync有什么区别呢?
browse.sync表示等待浏览器加载完成后进行下一步操作,浏览器加载完成的标志是浏览器显示左下角显示完成字样。
page.sync表示页面中所有的元素都已加载完成后,进入下一步的操作。
语法:object.Sync
示例:
Sub Sync_Example()
'The following example uses the Sync method to wait for the
'Mercury Tours page to synchronize.
before performing the next operation.
Browser("Mercury Tours").page("Mercury Tours").Sync
End Sub
2)WaitProperty
等待指定对象属性获得指定值或超出指定超时后再继续下一步。如果属性获得该值则返回 TRUE,如果在属性获得该值之前发生超时则返回 FALSE(注意:FALSE 返回值不表示步骤失败)
语法:object.WaitProperty (PropertyName, PropertyValue, [lTimeOut])
例1:Sub WaitProperty_Example()
'The following example uses the WaitProperty method to wait for the
'All kind of link's readyState to be complete or for
'4 seconds (4000 milliseconds) to pass, whichever comes first.
'If the link achieves this value before 4000 milliseconds pass,
'QuickTest clicks the link.
只有browse和page对象具有Sync方法,其它的对象都不具有该方法,那么browse.sync和page.sync有什么区别呢?
browse.sync表示等待浏览器加载完成后进行下一步操作,浏览器加载完成的标志是浏览器显示左下角显示完成字样。
page.sync表示页面中所有的元素都已加载完成后,进入下一步的操作。
语法:object.Sync
示例:
Sub Sync_Example()
'The following example uses the Sync method to wait for the
'Mercury Tours page to synchronize.
before performing the next operation.
Browser("Mercury Tours").page("Mercury Tours").Sync
End Sub
2)WaitProperty
等待指定对象属性获得指定值或超出指定超时后再继续下一步。如果属性获得该值则返回 TRUE,如果在属性获得该值之前发生超时则返回 FALSE(注意:FALSE 返回值不表示步骤失败)
语法:object.WaitProperty (PropertyName, PropertyValue, [lTimeOut])
例1:Sub WaitProperty_Example()
'The following example uses the WaitProperty method to wait for the
'All kind of link's readyState to be complete or for
'4 seconds (4000 milliseconds) to pass, whichever comes first.
'If the link achieves this value before 4000 milliseconds pass,
'QuickTest clicks the link.
If Browser("index").Page("index").Link("All kind of").WaitProperty("attribute/readyState", "complete", 4000) Then
Browser("index").Page("index").Link("All kind of").Click
End If
End Sub
例2:Sub WaitProperty_Example()
'The following example uses the WaitProperty method to wait for the
'Account edit box to be enabled before setting its value to 123.
'If it is still disabled after the test's
'Object Synchronization Timeout time has been exceeded, it will not
'perform. the Set method.
Browser("index").Page("index").Link("All kind of").Click
End If
End Sub
例2:Sub WaitProperty_Example()
'The following example uses the WaitProperty method to wait for the
'Account edit box to be enabled before setting its value to 123.
'If it is still disabled after the test's
'Object Synchronization Timeout time has been exceeded, it will not
'perform. the Set method.
If Browser("index").Page("index").WebEdit("Account").WaitProperty("disabled", 0) Then
Browser("index").Page("index").WebEdit("Account").Set ("123")
End If
End Sub
Browser("index").Page("index").WebEdit("Account").Set ("123")
End If
End Sub
3)wait
wait函数,当脚本走到wait函数时,就开始执行这个函数,如:wait(10),就等待10秒种后再继续执行下面的语句.wait函数的这个等待的时间,那相对来说是固定的,可能造成时间的浪费,或者等待时间的不足.
wait函数,当脚本走到wait函数时,就开始执行这个函数,如:wait(10),就等待10秒种后再继续执行下面的语句.wait函数的这个等待的时间,那相对来说是固定的,可能造成时间的浪费,或者等待时间的不足.
4)Exist
检查对象当前是否存在于打开的应用程序中。返回一个Boolean 值。
语法:object.Exist([TimeOut])
示例:
Do until SwfWindow("监测系统").SwfWindow("FormLoading").Dialog("提示").WinButton("确定").Exist(1800000)检查对象当前是否存在于打开的应用程序中。返回一个Boolean 值。
语法:object.Exist([TimeOut])
示例:
wait(2)
Loop
SwfWindow("监测系统").SwfWindow("FormLoading").Dialog("提示").Activate
SwfWindow("监测系统").SwfWindow("FormLoading").Dialog("提示").WinButton("确定").Click
在项目中根据不同的需要选择适合的函数或方法。
阅读全文
0 0
- QTP设置时延的方法
- QTP常用的方法
- 【QTP】最小化QTP运行的方法
- QTP访问DOM的方法
- QTP测试PDF的方法
- 重写QTP的Reporter方法
- QTP访问DOM的方法
- QTP访问DOM的方法
- QTP的终极破解方法
- QTP启用应用软件的方法
- qtp设置
- QTP如何设置Action的模板
- QTP脚本运行次数的设置
- QTP操作xml文件的方法
- 增强QTP调试器功能的方法
- QTP读取Excel数据的方法
- QTP测试Flash程序的方法
- QTP统计Excel列数目的方法
- Hive中小表与大表关联(join)的性能分析
- 微信扫码自动跳转技术
- java-web书中知识罗列
- Jenkins jmeter maven持续集成知识点
- 尝试Android的毛玻璃(Blur)效果
- QTP设置时延的方法
- php的数组与字符串的转换函数整理汇总
- 初写博客的一点分享
- react学习笔记-import花括号的使用
- Laravel项目.gitignore文件
- 《TCP/IP详解卷2:实现》笔记--IP:网际协议
- HDU1229(A+B)
- STL中的四个二分查找算法(binary_search lower_bound upper_bound equal_range)
- N皇后问题(回溯VS全排列)