规避QTP等待缺陷的一个函数

上一篇 / 下一篇  2009-03-27 20:19:36 / 个人分类:QTP

 

QTP等待有一定的缺陷,因此编写如下函数。

函数功能嘛,呵呵。各自发挥吧。有很多的用法哦。

如果不明白,可以加我QQ

 ______________________________________________________________________________

 '’
/*******************Function**************************/
'* 功能:等待语句为True值,如果超过预设的时间,则记入报告,退出测试
'* 输入参数:expectOrder:希望为True的语句
'*                           sWaitTime :等待的时间,单位为秒
'* 返回值:bool值,如果值等于预期,则返回true,否则返回false
'* 编写人:chenyb
'* 编写日期:2008-12-30
'* 其他说明:可以传入一个表达式,等待这个表达式的值为True
'/********************************************************/
Public Function WaitExcept(expectOrder,sWaitTime)
  On Error Resume Next
  Err.Clear
  '变量为:记录运行时间,匹配预期值的变量
  Dim totalTime,bolExist,bolCheck
  bolExist = False '默认表达式的值为false
  Execute "bolCheck = " & expectOrder  '给expectItem获取要匹配的值
  If Err.Number <> 0 Then
   bolCheck = False
   Err.Clear
  End If
  totalTime = 0
     Do while not  bolCheck  '如果语句运行结果不为True
    wait 0,100 '等待500毫秒
    totalTime =CDbl(totalTime) + 0.1 '记录等待的秒数
    If CDbl(totalTime) > CDbl(sWaitTime) Then '超过配置的时间就报超时
      Reporter.ReportEvent micWarning,"页面显示",expectOrder  & "--超时"'记录超时信息到报告
       bolExist = False'如果超时,则认为表达式的值为false
      Exit Do      
    End If
    Execute "bolCheck = " & expectOrder  '重新给expectItem获取要匹配的值
    If Err.Number <> 0 Then
     bolCheck = False
     Err.Clear
    End If
  Loop 
  If bolCheck Then  '如果表达式的值为True
   bolExist = True
  End If
  WaitExcept = bolExist '返回表达式的值的情况
  On Error Goto 0
End Function


TAG: 缺陷 QTP 等待 自动化测试

 

评分:0

我来说两句

chenyb85

chenyb85

大海无量。。。 QQ:20710378

日历

« 2024-04-16  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 18852
  • 日志数: 20
  • 建立时间: 2009-03-11
  • 更新时间: 2011-08-21

RSS订阅

Open Toolbar