Working with Recovery Scenarios using Scripting
To understand this topic you need to have knowledge on creating and using recovery scenarios.
In this document I am discussing about how to add, remove recovery scenario files (.QRS) to a test and after adding how to activate, deactivate and renumbering the order to execute recovery scenarios.
For example I have a recovery scenario file with the name of “sample .qrs”. Assume that in this recovery file I have two recoveries with the names loginPop, RunErr. (All of you know that one file can have multiple recoveries). Now if i want to use that file in my test then I have to use following script.
'*******************************************************************
' Create the Application object
Set qtApp = CreateObject("QuickTest.Application")
' Return the Recovery object for the current test
Set qtTestRecovery = qtApp.Test.Settings.Recovery
' Add the " loginPop " scenario as the first scenario
qtTestRecovery.Add "E:\Sudhakar\Recoveryfiles\sample.qrs", " loginPop ", 1
' Add the " RunErr " scenario as the second scenario
qtTestRecovery.Add "E:\Sudhakar\Recoveryfiles\sample.qrs", " RunErr ", 2
' Iterate the scenarios
For intIndex = 1 To qtTestRecovery.Count
' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
qtTestRecovery.Item(intIndex).Enabled = True
Next
' Enable the recovery mechanism (with default, on errors, setting)
qtTestRecovery.Enabled = true
'Ensure that the recovery mechanism is set to be activated only after errors
qtTestRecovery.SetActivationMode "OnError"
Set qtApp = Nothing ' Release the Application object
Set qtTestRecovery = Nothing ' Release the Recovery object
'*******************************************************************
With the above code automatically the recovery scenarios will be added to the specified test. After adding the scenarios if you want to control the scenario like changing the scenario status, to get the scenario name, to activate or deactivate we have to use recovery object (one of the Utility object).
Recovery Object
It is an utility object to control the recovery scenario mechanism programmatically during the run session.
It’s having some properties and methods to control the scenarios.
Associated Methods
1. Activate Method:
Explicitly activates the recovery scenario mechanism at a specific point in the run.
Note: The Activate method only works if the recovery mechanism is enabled, and only activates those recovery scenarios that are currently enabled.
If the recovery mechanism is currently disabled, the Activate method does not activate any recovery scenarios. You can use the Recovery object's Enabled property to change the status of the recovery mechanism.
Ex:- Recovery.Activate
Note: The Activate method only works if the recovery mechanism is enabled, and only activates those recovery scenarios that are currently enabled.
If the recovery mechanism is currently disabled, the Activate method does not activate any recovery scenarios. You can use the Recovery object's Enabled property to change the status of the recovery mechanism.
Ex:- Recovery.Activate
2. GetScenarioName Method:
Retrieves the name and source file of a recovery scenario, according to the specified position in the list of recovery scenarios associated with the test.
Ex:- Recovery.GetScenarioName Position, out_ScenarioFile, out_ScenarioName
Msgbox(out_ScenarioFile)
Msgbox(out_ScenarioName)
Ex:- Recovery.GetScenarioName Position, out_ScenarioFile, out_ScenarioName
Msgbox(out_ScenarioFile)
Msgbox(out_ScenarioName)
3. GetScenarioPosition Method
Returns the index position of a recovery scenario in the list of recovery scenarios associated with the test, according to the specified name and source file.
Ex:- Recovery.GetScenarioPosition (ScenarioFile, ScenarioName)
4. GetScenarioStatus MethodEx:- Recovery.GetScenarioPosition (ScenarioFile, ScenarioName)
Returns the status of a recovery scenario (True = enabled or False = disabled), according to the specified index position in the list of recovery scenarios associated with the test.
Ex:- Recovery.GetScenarioStatus Position
Ex:- Recovery.GetScenarioStatus Position
SetScenarioStatus Method
Enables or disables the specified recovery scenario, according to its index position in the list of recovery scenarios associated with the test.
Ex:- Recovery.SetScenarioStatus Position, Status
Ex:- Recovery.SetScenarioStatus Position, Status
Associated Properties
Count Property
Returns the number of recovery scenarios associated with the current test.
Ex:- msgbox Recovery.Count
Ex:- msgbox Recovery.Count
Enabled Property
Recovery default property. Retrieves or sets the status of the recovery scenario mechanism for the current test.
Ex:- Recovery.Enabled =Status
Ex:- Recovery.Enabled =Status
'********************************************************************
Sample Script
For Iter = 1 to Recovery.Count
Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName
Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )
Status = Recovery.GetScenarioStatus( Position )
Scenario=scenario& ScenarioFile&”:=”& ScenarioName&”,”&position&”,Status
NextPosition = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )
Status = Recovery.GetScenarioStatus( Position )
Scenario=scenario& ScenarioFile&”:=”& ScenarioName&”,”&position&”,Status
Msgbox Scenario
'********************************************************************
This code will show total scenarios in the QRS file, position and status of those scenarios.
Excellent example. Does this code need to be at the top or
ReplyDeletebottom of my QTP script. Does it have to be in a function. I am using this code and for whatever reason, the recovery code isn't being called on error. Any ideas
Excellent Example and one of best i read for this topic...thanks Sudhakar
ReplyDeleteThanks sudhakar
ReplyDelete