Situations in which a Recovery Scenario won't work - QTP

There are some situations in which a recovery scenarios won't work. Few of them are given below:
Case 1

Consider the script below:
'Recovery scenarios are only executed on statements
'containng QTP test objects
Dim x
x = 2
MsgBox x
Windov»("hwnd:=-l") .Exist(0)

Even if we enable the recovery scenarios to be run on "On Every Step", it will not be activated on the first three steps, but it will be activated on the 4th step, because QTP only activates recovery scenarios on code statements which contain QTP test objects. Any pure VBScript code error can't be handled using recovery scenarios. So we can either use a dummy step like Window("hwnd:=-1 ").Exist(0) or we call use the statement below at any position to force the activation of recovery scenario:

'Activate the recovery scenario Recovery.Activate

The above statement forces execution of all enabled recovery scenarios associated with current test.

Case 2

'Division by Zero
X = 2/0

As explained in Case 1 the above error will not cause a recovery scenario to be activated, and can only be handled using the "On Error Resume Next" statement as described earlier.

Case 3

'Access object not present in OR

In the above situation the object is not in the Object Repository and therefore can't trigger any recovery scenario. This type of exception occurs before QTP has a chance to execute the script's recovery scenario(s).

Case 4

A recovery scenario cannot close a dialog box initiated by code statement inside QTP. Consider the following code statements:

'Display a message box MsgBox
"Go to next statement"
'The next message box will not be displayed
'until user manually clicks the Ok button or
'some non-QTP program closes the dialog MsgBox "Passed"

When the above statements are executed in a script which has a recovery scenario to dismiss unexpected modal dialogs, the scenarios won't be activated. Neither Recovery.Activate nor QTP recovery itself can close these message boxes. They either need to be closed manually or they need to be closed by some other process outside QTP. Note that we will write a VBScript in "Working with APIs" chapter to achieve this.

Problem. How can we get the status of an Action as Pass/Fail at the end of the action?

The key here is to execute a recovery scenario whose recovery action is a function call and mark the Action as failed when the function gets called. Create a recovery scenario as given below:

Trigger Event:Test-Run error.
Error:Any Error Recovery Operation:
Operation type: Function Call
'Recovery function call
Function StatusUpdate(Object, Method, Arguments, retVal)
'Don't want to cause any error inside
'a recovery action function
On Error Resume
'Get the current action name. This is a user defined ,
'environment variable and has to be populated in every
sCurrentAction = Environment.Value("CurrentAction")
'Create a environment variable fiJr current action as failed
Environment.Value(sCurrentAction) = "Failed"
'Set the status for current test as failed
'This again is a user defined variable Environment.
Value("RunStatus") = "Failed"
End Function

Test Run options: Proceed to next step

Now in every action we start the action with code as given below:

'Disable all error messages
On error resume next
sCurrentActionName = DataTable.LocalSheet.Name
'Environment values cannot take a name vsith space or special
'chracters. Remove all special characters
sCurrentActionName = Replace(sCurrentActionName ," ", ""_")
sCurrentActionName = Replace(sCurrentActionName ," [", "_")
sCurrentActionName = Replace(sCurrentActionName ,"]", "_")
'Save the old action so that in case we call another action
'then the current action name is not lost sOldAction = Environment. Value("CurrentAction") Environment.Value("CurrentAction") = sCurrentActionName
'Initialize the status as Passed for the action Environment.
Value(sCurrentActionName) = "Passed" On error goto 0
And we end the action with below code as given below
'Once the action is completed make sure we set the
'action name back to earlier action Environment.Value("CurrentAction") = sOldAction
Now we can access the status of action as given below
'Access the status of the current action
DataTable("Status",dtGlobalSheet) = Environment.Value(sCurrentActionName)

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

QTP Topics