Automation object model in QTP (AOM)

Automation object model is nothing but structural representation of objects,methods and properties which are used to perform quicktest operations.Automation enables software packages to expose their unique features to scripting tools and other applications. You can use the QuickTest Professional Automation Object Model to write programs that automate your QuickTest operations.

QuickTest Professional is COM Server and its different methods and properties are exposed by its COM interface which can be accessed by other applications and scripting tools to control it from outside.

To create the automation object, we use “CreateObject” function. Once the object has been created, we can access all other objects, methods and properties of the QuickTest . CreateObject creates and returns the reference to an automation object.


You can write a script that modifies the test object description properties in the Object Identification dialog box and performs an update run on all tests in a specified file folder.

You can define your settings for a test in QuickTest, then click “Generate Script” in the Generate tab of the Test Settings dialog box to generate an automation script based on the current test settings. You can then apply those same settings automatically to multiple tests using the whole automation script or excerpts from the generated file.

Generating an automation script for QuickTest Professional options:

• Navigate to Tools > Options > General and click on the “Generate Scripts” buttons
• Navigate to File > Settings>Properties and click on the “Generate Scripts” buttons
• Navigate to Tools > Object Identification and click on the “Generate Scripts” buttons

Example:
Launch QTP, open an existing test and Run the Test and Store Run Results in Specified Folder:

Dim qtApp
Dim qtTest
Dim qtResultsOpt

'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")

'If QTP is notopen then open it
If  qtApp.launched <> True then

qtApp.Launch

End If

'Make the QuickTest application visible
qtApp.Visible = True

'Set QuickTest run options
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

'Open the test in read-only mode
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\AOMExamp;e", True

'set run settings for the test
Set qtTest = qtApp.Test

'Instruct QuickTest to perform next step when error occurs
qtTest.Settings.Run.OnError = "NextStep"

'Create the Run Results Options object
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")

'Set the results location
qtResultsOpt.ResultsLocation = "D:\AOMTestResult"

' Run the test
qtTest.Run qtResultsOpt

'Check the results of the test run
MsgBox qtTest.LastRunResults.Status

'Close the test
qtTest.Close

'Close QTP
qtApp.quit

'Release Object
Set qtResultsOpt = nothing
Set qtTest = Nothing
Set qtApp = Nothing