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
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.
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)
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
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 !