Launch QTP through VBScript

VBScript – Launch QTPAn update to our QTP knowledge. What I have below is a script that will enable the user to automatically open QTP and run the desired QTP function that could be coded within a vbs script.


Here is the script.
You can use this script to launch QTP automatically and run the scripts anytime from any place. No need to copy the scripts into your machine at all.

‘ This is a base function to launch QTP automatically and run the desired functions.
Dim qtApp ‘ defines the object to invoke the application through late binding technique
‘ To set the QTP late binding object. This object will be used to invoke the application QTP and associate a late binding connection to it.

Set qtApp = CreateObject(“QuickTest.Application”)

‘ Launching QTP. Invokes QTP through the connection defined earlier

‘ Ensuring that QTP is visible and available. It is an additional check to determine that the launch was successful.

qtApp.Visible = True

‘ Error if QTP is not launched. In case of QTP not being able to launch, the connection thread should be closed down and the reference to the application removed.

if err.number <> 0 then
msgbox “QTP could not be started”
end if

‘Run the function which contains the QTP script which is available within a vbs file

Set objFSO = CreateObject(“Scripting.FileSystemObject”) ‘ This is the file system object object to set a late binding connection to the system files

Set objFile = objFSO.OpenTextFile(“abhilash.vbs”, ForReading) ‘ Opens a text file “abhilash.vbs” for reading. This file contains the QTP scripts i.e. functions

Execute objFile.ReadAll() ‘ to read the contents of the vbs file.

‘ here abhilash.vbs contains the normal QTP scripts

‘QTP_Script1 will be a function name in the vbs which in turn contains the QTP SCRIPTS.

call QTP_script1() ‘This is a function within the vbs script abhilash.vbs

‘set qtp object as nothing.

set qtApp = nothing ‘ Once the function is executed, close QTP. Now another user can use the connection.

This are the contents of abhilash.vbs

function QTP_script1()
msgbox “abhilash”
End function


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