天天看點

QTP - 11-12 (Debugging in QTP ) 調試 & (Recovery Scenarios) 場景恢複11Debugging in QTP 調試12Recovery Scenarios 場景恢複

11Debugging in QTP 調試

11.1Establishing our Debugging Configuration:

              Beforeyou debugging, Go to ToolsàOptionsàRun (Tab)àCheck Run mode:(Normal)

 11.2Using Breakpoints:

               Click atLeft-Pane of Code window Or Press F9.

Note: Following three tabs in the Debug Viewer:

11.3Working with the Watch Expressions Tab:

               優點比較智能化的結果。在左欄添加你想要的variablesand the statements, QTP 在右欄顯示出結果。比如左欄Len(Str1), 右欄會顯示出Str1的長度。

11.4Working with the Variables Tab:

               顯示出所有腳本中出現的變量和值。

11.5Working with the Command Tab:

               與QTP系統互動,可以改變QTP的code.(e.g.比如你在CommandTab 下輸入y=”command”, 那麼y的值就改成了”command”)

12Recovery Scenarios 場景恢複

Concept: QTP recovery scenarios recover from runtime errorconditions.

12.1 When to userecovery scenarios:

               A recovery scenario consists offollowing components:

*A Trigger Event:

--Pop-up window

--Object State

--Test run error

--Application crash

*A Recovery action:  (action if the event triggered)

--Keyboard or mouse operation

--Close application process

--Function call

--Restart Windows

*Post Recovery: (what should be done after recovery action completed)

--Repeat current step and continue

--Proceed to next step

--Proceed to next action iteration

--Proceed to next test iteration

--Restart current test run

--Stop run

12.2 How to userecovery scenarios:

               Resourcesà recovery scenarioManager àNew recovery scenarioàFollow its guide

12.3 Situations in which arecovery scenario won’t work

               VBS errors;a dialog box by QTP (e.g Msgbox)

12.4 How can we get the status of an Action as Pass/Fail at the end of theaction?

               思路: 設定一個statue環境變量(值為pass), 設計一個隻要有error就會觸發的recoveryscenario,它的Recoveryaction 調用一個function: 這個function把statue= fail。

'A Recovery action(Function call)

Function StatusUpdate(Object, Method, Arguments, retVal)

   On Error Resume Next

   sCurrentAction = Environment.Value("CurrentAction")                   'get current action name

   Environment.Value(sCurrentAction) = "Failed"                   'new environment variable

End Function

'At each Action begin code

On Error Resume Next

               sCurrentActionName = DataTable.LocalSheet.Name                         'Get action name

               sOldAction = Environment.Value("CurrentAction")

               Environment.Value("CurrentAction") = sCurrentActionName

               Environment.Value(sCurrentActionName) = "Passed"

On Error Goto 0

'At each Action end code

Environment.Value("CurrentAction") = sOldAction

'sCurrentActionName  is the status of the Action

12.5 DefaultRecovery Scenarios

在安裝目錄“ProgramFiles (x86)\HP\QuickTest Professional\dat\BPT_Resources\DefaultWeb.qrs”有系統為web預設的recoveryscenarios,(包含Internet Redirect, Security Warning, Security Information, Security Alert, Filedownload)。如需要,直接加即可。

12.6 The Recovery Object

The Recovery object provides control recovery scenario.

Method:

Add ; Find ; MoveToPos ; Remove ; SetActivationMode Add           

Properties:

Count; Enable; Item

12.7 Recovery action (Function call)

根據不同的EventTrigger, Recovery Function 的參數是不一樣的,除一下function其他格式的function不能做RecoveryFunction:

Trigger – Test Error Run

Function RecoveryFunction1(Object, Method, Arguments, retVal)

Object – the object of the current step

Method – The method of the current step

Arguments – The actual method’s arguments as arrays

Result – The actual method’s result code

Trigger – pop-up window & Object Statues

Function RecoveryFunction2(Object)

Object – The detected object

Trigger – Application crash

Function RecoveryFunction3(ProcessName, ProcessId)

ProcessName – The detected process’s Name

ProcessID – The detected process’ ID

e.g. RecoveryFunction1

Function RecoveryFunction1(Object, Method, Arguments, retVal)

    Select Case Method

                  Case "Set"

                          Select Case Object.GetTOProperty("micclass")

                                          Case "WebList"

End Function

12.8 Error Handling

1. 如果加上 “OnError Resume Next” 對這句話下面的錯誤就不會報錯。直到“OnError Goto 0

”恢複報錯。

2. VBS not support ‘On Error goto’ statements, but we canachieve by following code.

Helpful when create framework where external sheets are usedto run keywords.

Here is the example code:

Dim GlobalErrHanlder

Function FuncWithError()

               Dim x, y

               x = 2 + 4

               y = x -2 -4

               x = x/y

End Function

'Error wrapper function, helpful to create framework

Function FuncWithErrHanlder()

   Call FuncWithError()

   If Err.Number <>0 Then

                              Call globalErrHandler()

   End If

End Function

'Update gloabal error hanlder module function

Function OnErrorGoTo(ByVal FunctionName)

   Set globalErrHandler = GetRef(FunctionName)

   ‘GetRef method: globalErrHandler is now the function named “FunctionName”

End Function

Function errHanlder()

   print Err.Number & Err.Source & Err.Description

End Function

'Set the global errHandler code

OnErrorGoto "errHandler"

'Execute the Error wrapper function

Call FuncWithErrHanlder()

繼續閱讀