QTP中与时间同步点:Sync、Wait、Waitproperty、Exist

上一篇 / 下一篇  2011-06-15 10:14:48 / 个人分类:QTP自动化测试

同步点是QTP是很重要的一部分。常用的同步点方法有以下几种:
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.
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.
If Browser("index").Page("index").WebEdit("Account").WaitProperty("disabled", 0) Then
    Browser("index").Page("index").WebEdit("Account").Set ("123")
End If
End Sub

3)wait
wait函数,当脚本走到wait函数时,就开始执行这个函数.如:wait(10),就等待10秒种后再继续执行下面的语句.wait函数的这个等待的时间,那相对来说是固定的,可能造成时间的浪费,或者等待时间的不足.

4)Exist
检查对象当前是否存在于打开的应用程序中。返回一个Boolean 值。
语法:object.Exist([TimeOut])
示例:
Sub Exist_Example()
'The following example uses the Exist method to determine the
'existence of the "Mercury Tours" browser. If the object exists,
'a message box appears confirming its appearance.
If Browser("Mercury Tours").Exist Then
  MsgBox "The browser exists."
End If
End Sub
在项目中根据不同的需要选择适合的函数或方法。
 

 

TAG: exist Exist QTP qtp Sync Wait Waitproperty

 

评分:0

我来说两句

日历

« 2024-04-30  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 23176
  • 日志数: 1
  • 文件数: 3
  • 建立时间: 2011-02-20
  • 更新时间: 2011-08-14

RSS订阅

Open Toolbar