Showing posts with label QTP Automation Object Model. Show all posts
Showing posts with label QTP Automation Object Model. Show all posts

Friday, December 24, 2010

Recovery Scenarios using VB Scripting

Working with Recovery Scenarios using Scripting

Precondition:-
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:\TEST\Recoveryfiles\sample.qrs", " loginPop ", 1
' Add the " RunErr " scenario as the second scenario
qtTestRecovery.Add "E:\TEST\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

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)

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 Method
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

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

Associated Properties
Count Property

Returns the number of recovery scenarios associated with the current test.
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

'********************************************************************
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
Next
Msgbox Scenario
'********************************************************************
This code will show total scenarios in the QRS file, position and status of those scenarios.

Thursday, December 23, 2010

Automation Object Model

'Open QTP and Connect to Quality Center  
'************************************************************************************************* 
Dim qtApp ' Declare the Application object variable  
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object  
qtApp.Launch ' Start QuickTest  
qtApp.Visible = True ' Make the QuickTest application visible  

' Make changes in a test on Quality Center with version control  
qtApp.TDConnection.Connect "QC URL", "DOMAIN Name", "Project Name", "User Name", "Password", False ' Connect to Quality Center     
 
If qtApp.TDConnection.IsConnected Then ' If connection is successful  
 MsgBox "Succesfully connected to Quality Center" 
Else 
    MsgBox "Cannot connect to Quality Center" 
End If 

qtApp.Quit ' Exit QuickTest  
Set qtApp = Nothing ' Release the Application object  
'************************************************************************************************* 
'*************************************************************************************************
'Start  QTP and open New test  
'*************************************************************************************************
'************************************************************************************************* 
Dim qtApp ' Declare the application object variable  
Set qtApp = CreateObject("QuickTest.Application") ' Create the application object  
 
qtApp.Launch ' Start QuickTest  
qtApp.Visible = True ' Make the QuickTest application visible  
 
qtApp.New ' Open a new test  
 
Set qtApp = Nothing ' Release the Application object  
'************************************************************************************************* 
'*************************************************************************************************  
'Start  QTP, open an existing test and Run the Test  
'*************************************************************************************************  
'*************************************************************************************************  
Dim qtApp  
Dim qtTest  
 
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object  
qtApp.Launch ' Start QuickTest  
qtApp.Visible = True ' Make the QuickTest application visible  
 
' Set QuickTest run options  
qtApp.Options.Run.ImageCaptureForTestResults = "OnError" 
qtApp.Options.Run.RunMode = "Fast" 
qtApp.Options.Run.ViewResults = False 
 
qtApp.Open "C:\Tests\Test1", True ' Open the test in read-only mode  
 
' set run settings for the test  
Set qtTest = qtApp.Test  
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs  
 
qtTest.Run ' Run the test  
 
MsgBox qtTest.LastRunResults.Status ' Check the results of the test run  
qtTest.Close ' Close the test  
 
Set qtTest = Nothing ' Release the Test object  
Set qtApp = Nothing ' Release the Application object  
'*************************************************************************************************