How to use Recovery Scenario in QTP/UFT with Example
โก Smart Summary
Recovery scenarios instruct UFT One to detect an unexpected event during a run session, perform a corrective operation, and then continue the test automatically instead of pausing an unattended run until somebody intervenes.
Using Recovery Scenarios you can instruct UFT One to recover from unexpected events and errors that occur in your Testing environment during a run session.
Recovery scenario becomes crucial for large tests, which run unattended and are paused until a recovery operation is performed, increasing the test execution time.
⚠️ Product naming: the tool in this guide shipped as HP QuickTest Professional (QTP), became HP Unified Functional Testing, then Micro Focus UFT One, and is now sold by OpenText. The menu paths below are unchanged, so the steps still apply.
Steps to use Recovery Scenario in QTP/UFT
There are 6 steps involved in creating a recovery scenario
Step 1) In UFT One, Select Resources > Recovery Scenario Manager. Create new Scenario
Step 2) Specify the Trigger Event. A Trigger Event is an event that interrupts your run session
Step 3) Specify the Recovery Operation which is the corrective action you take when the trigger happens
Step 4) Specify Post-recovery test run options which specify how to continue the run session after Quick Test Professional has identified the event and performed all of the specified recovery operations.
Step 5) Check and verify Summary of the scenario you created.
Step 6) Add Recovery Scenario to your test using File > Settings > Recovery. The test results window show the details of the recovery scenario
Following video explains the steps in detail
Click here if the video is not accessible
Note: the wizard does not fire for a trigger that occurs in the very last step of a test. Add a spare step at the end when the final action can fail.
Trigger Events Supported by UFT One
Step 2 above asks for a trigger event, and the wizard offers exactly four kinds. Choosing the right one matters, because each type recognises the interruption in a different way.
| Trigger event | How UFT One recognises it | Typical example |
|---|---|---|
| Pop-up window | Window title and the text inside the window | A “printer out of paper” message box |
| Object state | Property values of the object and of all its ancestors | A button that is disabled while another process is open |
| Test run error | A failed return value from a method | A menu item that is missing at that point in the run |
| Application crash | A predefined list of applications | A secondary application that closes mid-run |
An object state trigger is matched per object, so if two objects reach the same state the recovery operations run twice, once for each match.
Recovery Operations and Post-Recovery Run Options
Steps 3 and 4 define what happens once the trigger fires. The recovery operation is the corrective action, and UFT One supports four of them.
- Keyboard or mouse operation โ click a named button in the window or send a key combination.
- Close application process โ pick one or more running processes from the list and end them.
- Function call โ run a VBScript function stored in an associated function library.
- Restart Microsoft Windows โ the heaviest option, reserved for an unrecoverable environment.
Several operations can be queued in one scenario, and they execute in the order listed. The post-recovery option then tells the run session where to resume.
- Repeat current step and continue
- Proceed to next step
- Proceed to next action iteration
- Proceed to next test iteration
- Restart current test run
- Stop the test run
Pick Repeat current step when the pop-up simply blocked a click, and Proceed to next test iteration when the data row itself is the problem. A scenario saved through the wizard is stored in a .qrs file, so several tests can share it, and the order of scenarios attached to a test decides which one is applied first.
Handling Errors with On Error Resume Next
A recovery scenario answers an event nobody predicted. A predictable failure โ a missing file, a value that fails to set โ is cheaper to trap inside the script itself with VBScript error handling.
Use can also use statements
- On Error Resume Next : execution continues on the next line instead of stopping, and the failure is recorded in the Err object.
- On Error GoTo 0 : the default behaviour returns, so any later error stops the run again.
to handle errors in your script
The two statements work as a pair. Open the guarded region, check Err.Number straight after the risky line, report the result, clear the object, then close the region.
On Error Resume Next SystemUtil.Run "notepad.exe" If Err.Number <> 0 Then Reporter.ReportEvent micWarning, "Launch application", Err.Description Err.Clear End If On Error GoTo 0
Note: VBScript has no On Error GoTo <label>. Only Resume Next and GoTo 0 are valid, and the setting applies to the current procedure only.
| Situation | Better choice |
|---|---|
| Random pop-up or application crash | Recovery scenario |
| A single step that may legitimately fail | On Error Resume Next |
| Unattended overnight suite | Recovery scenario, so the run never waits |
| Validation that must be reported per step | On Error Resume Next with Reporter.ReportEvent |
