0 Shares 4000 Views 1 Comments

Automation Object Model : QuickTest Professional

Jan 30, 2013
4000 Views 1

QTP_Logo

[ws_table id=”2″]

An Object Model is a structural representation of objects that comprise the implementation of a system or application. Automation enables software packages to expose their unique features to scripting tools and other applications. Usually Automation uses the Component Object Model (COM). A critical aspect of COM is, how client and servers interact. A COM server is any object that provides services to clients; these services are in the form of COM interface implementations like Properties, Methods, Events and their relationships. Which can be called by any client that is able to get a pointer to one of the interfaces on the server object.

QuickTest Professional is also a 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. In this post, we will see how to interact with QTP from outside via Automation Object Model.

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.
Syntax:
CreateObject (Servername.typename [, location])

[ws_table id=”1″]

Launching QTP, opening & executing an existing test case and closure of QTP
In this scenario, QTP is launched automatically with default addins i.e. (Web, ActiveX and VB) ,execution of the test case and then exit from QTP

In the code snippet below, COM interface for QTP has been retrieved using the “CreateObject” function. After creating the object, it has been  checked whether the QTP is launched or not, if not then launch the QTP. Once the QTP is launched, to make it visible we have set the visible property of the QTP as True.

Dim qtApp
Dim qtTest
Set qtApp = CreateObject("QuickTest.Application")
If qtApp.launched <> True then
qtApp.Launch
End If
qtApp.Visible = True

Now, we need to set the various parameters for execution of the test case i.e. when the error occurs, capture the error. Set the Run mode and  the result settings, in this code we set the flag as false to not to open the result after execution.

qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

In the next section of code, we are opening the test, the test can be opened in two mode i.e. read only or edit mode. Here, we have mentioned the flag as true which opens the test in the read only mode. After opening the code, we create the object for the execution and instructs QTP what needs to be done in case of error. And finally run the test using .Run method and at last check the status of the execution i.e. testcase passed or not.

qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", True
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep"
qtTest.Run
MsgBox qtTest.LastRunResults.Status

After the execution, we have to close the test first and then close the QTP using .quit method. In the end we need to release the object using Set Objectname=nothing.

qtTest.Close
qtApp.quit
Set qtTest = Nothing
Set qtApp = Nothing

Here is the complete code for reference.

Dim qtApp
Dim qtTest
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is not open then open it
If qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
'Set QuickTest run options
'Instruct QuickTest to perform next step when error occurs
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\trial", 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"
'Run the test
qtTest.Run
'Check the results of the test run
MsgBox qtTest.LastRunResults.Status
' Close the test
qtTest.Close
'Close QTP
qtApp.quit

‘Release Object
Set qtTest = Nothing
Set qtApp = Nothing

Copy the above code in a notepad and save the notepad with .vbs extension and execute.

Some of the scripts which can be generated inside QTP at settings tab :

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

You may be interested

UFT Patch Updates – UFT 14.03
Unified Functional Testing
960 views1
Unified Functional Testing
960 views1

UFT Patch Updates – UFT 14.03

Saket - Mar 11, 2018

Post the launch of UFT 14.0, there are three patch updates has been released including a number of features and enhancement. Recently Micro Focus unveiled third patch…

Setting up Web Service Automation Project
Katalon Studio
1124 views
Katalon Studio
1124 views

Setting up Web Service Automation Project

Saket - Oct 24, 2017

Web services are specific services that can be published and called over the Internet by client applications. Katalon Studio supports functional testing of web services. This topic…

Setting up Mobile Automation Project in MacOS
Katalon Studio
996 views1
Katalon Studio
996 views1

Setting up Mobile Automation Project in MacOS

Saket - Oct 09, 2017

Using Katalon Studio, mobile tester can design automation test for both Android and iOS to run on physical devices, cloud services and emulators. This tutorial explains how…

One Comment

  1. Pingback: All About Object Models in QTP / UFT - Automated360

Leave a Comment

Your email address will not be published.

Most from this category

Join The Growing Group of 15000+ Test Automation Engineers

Signup for our newsletter and get access to free downloads, as well as tips, tricks and techniques and various test automation resources.
Name
Email Address
Secure and Spam free...