规避QTP等待缺陷的一个函数-自动化测试
更新时间:2022-05-26 09:06:33 作者:多测师 浏览:198
QTP等待有一定的缺陷,因此编写如下函数。
_________________________________________________________________________
''
/*******************Function**************************/
'* 功能:等待语句为True值,如果超过预设的时间,则记入报告,退出测试
'* 输入参数:expectOrder:希望为True的语句
'* sWaitTime :等待的时间,单位为秒
'* 返回值:bool值,如果值等于预期,则返回true,否则返回false
'* 编写人:lfc
'* 编写日期:2022
'* 其他说明:可以传入一个表达式,等待这个表达式的值为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
以上内容为大家介绍了自动化测试中的规避QTP等待缺陷的一个函数,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/