VBScript - Launch QTP
An 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
qtApp.Launch
' 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"
qtApp.quit
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
Hey there!!! I am really very eccentric as my blogname suggests. Wanna get a dose of eccentricity. C'mon. Welcome to the eccentric place of Abhilash. | Welcome to the Eccentric Place. | Such a lovely place, such a lovely place. | Plenty of room at this eccentric place. | You can check out anytime you like but you can never leave. | A place for Software Testing basics, Health Tips and Weight Training tips.
Tuesday, October 28, 2008
Subscribe to:
Post Comments (Atom)
Calorie Calculator
Calculate how much you expend in 1 hour of your favorite exercise.
Health Tips.
No comments:
Post a Comment
Drop in your comments/ feedback