軟件測試工具QTP中運行錯誤的捕捉和記錄

發表于:2010-02-01來源:作者:點擊數: 標簽:軟件測試工具qtpQTP記錄
軟件測試工具 QTP 中運行錯誤的捕捉和記錄 在自動化程序的運行過程中,經常因為環境問題或者代碼本身不完善而出現流程不能順利進行下去的情況,或者會有一些“隨機”的提示框(如“操作太快,頁面不能及時處理”),這時QTP會產生錯誤提示,對于這些提示,完

軟件測試工具QTP中運行錯誤的捕捉和記錄  

在自動化程序的運行過程中,經常因為環境問題或者代碼本身不完善而出現流程不能順利進行下去的情況,或者會有一些“隨機”的提示框(如“操作太快,頁面不能及時處理”),這時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

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97