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

发表于:2009-6-23 16:10

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing博客

  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

 

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号