QTP等待有一定的缺陷,因此编写如下函数。
函数功能嘛,呵呵。各自发挥吧。有很多的用法哦。
_________________________________________________________________________
''
/*******************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 |