SelfTechy

A portal for self learning

Tag Archives: Exception Handling

QTP – Recovery Scenario


Execution of automated test cases might result in some unexpected error conditions. In such situations, QTPs error handling feature Recovery Scenario comes in handy.

To create a Recovery Scenario, we need to configure the below steps:

  1. Trigger Event
  2. Recovery Operation
  3. Post-Recovery Test Run Options
  4. Name and Description of the Recovery Scenario
  5. Finish

Click Resources –> Recovery Scenario Manager

RecoveryScenarioMenu

Click on the New Recovery Scenario icon

CreateRecoveryScenario

Click Next button on Recovery Scenario Wizard

RecoveryScenarioWelcome

Select the Trigger Event

RecoveryScenarioTriggerEvent

Following are the different Trigger Events available:

  1. Pop-up window
  2. Object state
  3. Test run error
  4. Application crash

We will discuss only one trigger event in this post:

Pop-up window

After performing certain operation, sometime we might expect a popup window. If the popup window is blocking the execution QTP throws “Object is disabled” Run error. This is because QTP is not able to identify the object in the next step. Hence, to overcome this situation we can use Recovery Scenario.

To demonstrate the above situation, we will record “Update order” scenario in Flight application.

  1. Open the flight application
  2. Enter valid username / password
  3. Open the record with a date 12/12/12 (This record has to be created earlier with Insert order scenario)
  4. Edit the date once the record is opened (just try to delete 12 and then re-enter the same)
  5. Click update order
  6. It throws the error
  7. Without clicking the OK button on the error popup QTP will throw “Object disabled error”
  8. Here we need a recovery scenario

Create a Recovery Scenario as below:

  1. As explained above, get the error popup first
  2. Then Click on Resources –> Recovery Scenario Manager
  3. Click on New Icon
  4. Click Next
  5. Select Popup window radio button & click Next
  6. Specify pop-up window conditions –> Click on Hand button and click on the required error popup
  7. Window Title and Window Text are captured
  8. Click Next and Select Keyboard or mouse operation
  9. Select “Click button with label” and show the OK button on the popup
  10. Click Next
  11. Click Add Another recovery operation (This is because after clicking the OK button on the popup QTP does not close the application)
  12. Select “Close application process”
  13. Select the process “flight4.exe” and click Add button
  14. Click Next (Recovery operations should have two processes)
  15. Click Next
  16. Post Recovery Test Run Options –> Select Proceed to next step
  17. Click Next and specify a name & description
  18. Click Finish & Save the scenario

Refer the below screenshots:

SpecifyPopupWindow

WindowSpecified

AddApplicationProcess

RecoveryOperations

Record the script:

'Script "Updates an existing Order in the Flight application 
'uses date to select the record
'purpose - to demonstrate recovery scenario
'Author - Seetaram Hegde
'Copyrights - All rights reserved

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").SetSecure "4e987848731bb27320f898d8e4cc58977b0d6b69"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON"
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Click 4,6
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "21212"
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Click 5,7
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "0" +  micLeft
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "0"
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type  micBack
Window("Flight Reservation").Dialog("Open Order").ActiveX("MaskEdBox").Type "1"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type  micDel
Window("Flight Reservation").ActiveX("MaskEdBox").Type  micDel
Window("Flight Reservation").ActiveX("MaskEdBox").Type "12"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinButton("Update Order").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Save the Test as “UpdateOrderRecovery”

Associate the newly created Recovery Scenario with this test.

  1. Click File –> Settings –> Click on Recovery Tab
  2. Click Add (+) button and add the recovery scenario
  3. From the “Activate Recovery Scenarios” dropdown select “On error”
  4. Click OK

Execute the test and it should first click on the error popup window and then close the flight application.