QTP LR JSP ORACLE

[转载]QTP中运行错误的捕捉和记录

上一篇 / 下一篇  2010-06-07 16:30:01 / 个人分类:QuickTestProfessional

  在自动化程序的运行过程中,经常因为环境问题或者代码本身不完善而出现流程不能顺利进行下去的情况,或者会有一些“随机”的提示框(如“操作太快,页面不能及时处理”),这时QTP会产生错误提示,对于这些提示,完全忽略不可取,最好的是及时记录当前错误内容,重复当前操作,当错误提示累计到一定数量,中止当前流程。

  本文提供一种QTP运行错误的捕捉和记录方法,结合QTP本身的场景恢复机制,可以很好的解决该问题。

  首先在恢复场景中定义场景恢复策略,选择需要捕捉的错误种类,定义捕捉错误后的处理,此处定义一个异常处理函数。

  函数定义如下:


‘ Object-出错对象;Method-对象当前的方法;Argu-对象当前方法的参数;retval-当前错误的返回值(errCode)
Function RecordErr(Object, Method, Arguments, retVal)
       wait 3
       Dim ErrCode,ErrDesc,ArgCount,WrongInfo,ArgList
       Dim i,blankStr,ErrCount,CurRow
      
       ‘ 在Globaltable中记录累计错误数
       CurRow = DataTable.GlobalSheet.GetcurrentRow
       DataTable.GlobalSheet.SetcurrentRow 1  
   
    If Environment ("ActionName")<> datatable.Value("CurAction",dtGlobalSheet) Then
              datatable.Value("CurAction",dtGlobalSheet) = Environment ("ActionName")
              datatable.Value("ErrCount",dtGlobalSheet) = 0
       End If
   
       ErrCount = CInt (datatable.Value("ErrCount",dtGlobalSheet))
       blankStr = "                                  "
   
       ErrCode = retVal
       If ErrCode = 0 Then
              ErrDesc = "不明错误!"
       Else
              ErrDesc = DescribeResult(ErrCode)
       End If
 
       ArgCount = UBound(Arguments)
       For i = 0 to ArgCount
        ArgList = ArgList & CStr(i) & "--" & CStr(Arguments(i)) & "/"
       Next
      
       On Error Resume Next
       ‘ 获取对象错误具体描述,此处使用了对象较通用的name属性,部分对象没有该属性可能出错
       WrongInfo = "Object Name: " & Object.GetTOProperty("name") & vbCrLf _
                   & blankStr & "Current Method: " & Method & vbCrLf _
                   & blankStr & "ArgList: " & ArgList & vbCrLf _
                   & blankStr & "ErrDesc: " & ErrDesc
 
       On Error GoTo 0   
    GE_logError "对象运行中出现错误--" & WrongInfo,micFail   
   
    Err.Clear
   
ErrCount = ErrCount + 1
 
    ‘ 累计错误达5次后退出当前流程
    If ErrCount >= 5 Then
              ErrCount = 0
              datatable.Value("ErrCount",dtGlobalSheet) = ErrCount
              DataTable.GlobalSheet.SetcurrentRow CurRow
              routingname = ""
              GE_logError "*****运行过程错误过多,退出本Aciton Iteration,请运行完成后检查环境和脚本!*****",micFail
              ExitActionIteration
       End If
 
       datatable.Value("ErrCount",dtGlobalSheet) = ErrCount
       DataTable.GlobalSheet.SetcurrentRow CurRow
      
End Function


TAG:

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 71492
  • 日志数: 117
  • 图片数: 1
  • 文件数: 1
  • 建立时间: 2007-05-07
  • 更新时间: 2011-06-16

RSS订阅

Open Toolbar