preload

Managing Recovery Scenarios (QTP, VBScript)

Posted by Albert Gareev on Dec 16, 2008 | Categories: RobustnessSource code

As promised, I’m writing more detailed post on QTP Recovery Scenario management.

Overview

Exception / Event Handlers in QTP are declared as “Recovery Scenarios” through wizard dialogs and editable with Recovery Scenario Manager.

All exception handlers must be added to test script to use them.

Programmatically exception handlers are accessible through Recovery object.

During run-time, exception handlers can be enabled or disabled. Disabled handler does not impact QTP performance.

Object-Oriented Approach

Let’s start with declaration of a Handler object. For simplicity, I’ll use public access properties and methods.

Exception Handler


'Exception Handler
Class tpExceptionHandler
   Public SelfName 'Name to report
   Public Position 'Position index
   Public Target 'Object reference - Pop-up Window or Dialog
   Public Cases ' Exception Cases list (Dictionary)
End Class

Although exception handlers are always hooked on specific GUI window, applications usually re-use same window to display different kinds of messages.

Each Exception Case defines one possible message displayed by an application-under-test.

Exception Case


'Exception Case
Class tpExceptionCase
   Public SelfIndex
   Public Response
   Public State
End Class

Methods

Each object class needs initialization methods.


 Public Function DefineHandler(ByVal sName, ByVal intPos)
    Dim objExceptionHandler
    Set objExceptionHandler = new tpExceptionHandler
    objExceptionHandler.SelfName = sName
    objExceptionHandler.Position = intPos
    Set objExceptionHandler.Cases =  CreateObject("Scripting.Dictionary")
   
    Set DefineHandler = objExceptionHandler
 End Function

'......

 Public Function DefineExceptionCase(ByVal sCaseIndex, ByVal sResponse, ByVal intState)
    Dim objExceptionCase
 
    Set objExceptionCase = new tpExceptionCase
    objExceptionCase.SelfIndex = sCaseIndex
    objExceptionCase.Response = sResponse
    objExceptionCase.State = intState
 
    Set DefineExceptionCase.Cases.Item(sCaseIndex) = objExceptionCase
 End Function

Tying QTP Recovery Scenarios to Object Model


intPos = Recovery.GetScenarioPosition("API\Exceptions\AppExceptions.qrs", "Handler1")
Set objHandler1 = DefineHandler("Handler1", intPos)

Set objHandler1.Target  = Window("App Main").Dialog("Warning")

'Note: you may also use Descriptive Programming notation to define Target

intPos = Recovery.GetScenarioPosition("API\Exceptions\AppExceptions.qrs", "Handler2")
Set objHandler2 = DefineHandler("Handler1", intPos)

Set objHandler2.Target  = Window("App Main").Dialog("Error")

'Note: you may also use Descriptive Programming notation to define Target

'....

'We can define and add Exception Cases at any point of execution

Set objXCPCase1 = DefineExceptionCase("error_message1", "Invalid password", micFAIL)
Set objHandler2.Cases.Item(objXCPCase1.SelfIndex) = objXCPCase1

Activate / Deactivate Exception Handlers

Enable


Recovery.SetScenarioStatus objHandler1.Position, True

Disable


Recovery.SetScenarioStatus objHandler1.Position, False


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.