How to Automate QTP itself ?

We can use VBScript and automate QTP itself.  The concept that is used is called AOM (Automation Object Model). You are at the correct page if you want to do anything like :-

1. Schedule a QTP script to run at a specific time.

2. Want QTP script to run by executing a VBS/clicking a button on a Macro.

3. Want to do Continuous Integration with a tool like Jenkins.

In order to accomplish these things mentioned above, you need to understand what is AOM. An object model is a collection of objects or classes through which a program can examine and manipulate some specific parts of its environment. So QTP’s Automation Object Model gives us exposure to certain objects and their methods and properties which enable us to manipulate it.

A plain VBS file can be used to invoke QTP and run a script in the following manner :-
Set qtApp = CreateObject(“QuickTest.Application”)         ‘Create the QTP Object

qtApp.Visible = True                 ‘Make it visible

If qtApp.launched <> True Then         ‘Launch it if its not launched
End If

qtApp.Open “C:\MyTestScript”           ‘Open a script

Set qtTest = qtApp.Test                  ‘Create a Test Object
qtTest.Run , False               ‘Here false indicates that the control should be passed back to the vbs file after Test execution has started.



Set qtApp=Nothing

So this was the basic stuff. If you have got this right, I’m sure you must be hungry for a lot more ! Here are some code snippets that might be useful for you :-

1. Opening and Running QTP on a remote machine :-

Set qtApp = CreateObject(“QuickTest.Application”,machineName)   

rest everything remains the same except that it will run on the given machine

2. Sending environment variables to QTP Script :-

‘these variables can be used in the script that is invoked through AOM

3. Getting the Addins associated with your QTP Test :-

arrAddins = qtApp.GetAssociatedAddinsForTest(“C:\Test1″)
For i=0 to ubound(arrAddins)
    Print arrAddins(i)

4. Setting mode to On Error Resume Next :-


5. Add Function Libraries dynamically :-

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries 

'If the library file "lib1.vbs" is not associated with the Test, then associate it

If qtLibraries.Find(“D:\lib1.vbs”) = -1 Then
    qtLibraries.Add “D:\lib1.vbs”, 1
End If

I think you should be able to figure out now that how we can use the above code to things that I mentioned in bold at the start of this article. I will be writing separate posts in order to simplify them.

Happy Automating !

Harshit Kohli


10 thoughts on “How to Automate QTP itself ?

  1. could you tell me how to define run setting for QTP in VB script file.If i want to run script for only 2 datatable not to set those in vb script

  2. Hi Harshit,
    I am trying automate the use of some keyboard shortcuts that are used in QTP via Excel Macro.Eg: Alt+O+R : opens the object repository.
    there are other ways to open OR too but that’s not the point.
    Can you please help me automate an keyboard shortcut entry on QTP window?

  3. Hi, I want to schedule UFT script to run every day at 6:30am 2:30PM and 10:30PM, this script shakeout UI applications and capture the result and send an email.
    Can someone please help me to write a VBScript
    Thanks much

  4. Hi Harshit,

    Set qtApp = CreateObject(“QuickTest.Application”,”PawanTestMachine”)

    The above line gives an error ActiveX component can’t create object: ‘QuickTest.Application’

    I have two VMs (Virtual machines ) of Windows server 2012R2, 1 machine has licenced UFT 12.01 installed in it, and other machine is just to run scripts (in .vbs file).
    I have done COM settings and both machines are in same domain.
    The above line gets executed successfully if i run the same on local machine.
    Any advice ?


      1. Thanks Harshit for your immediate reply 🙂
        i tried with Machine IP too, and tried on other machines too, same error.
        Also i am using Windows Server 2012R2, i hope that does not make any misbehaviour.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s