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() |