How to Execute QTP script from Command Prompt using Automation Object Model
By Parul Wahi
In order to run QTP scripts on schedule, we can run them directly from command line.
In order to do so we can make use of QTP Automation Object Model which can help us in automating QuickTest operations. Using the objects, methods, and properties exposed by the QuickTest automation object model, we can write scripts that configure QuickTest options and run tests instead of performing these operations manually using the QuickTest interface.
In the following code we are trying to execute a QTP script called “Google_search” from command line. Let’s create a script in QTP and save it as Google_search.Write the following code in a vbs (VB Script) file as save it as demo.vbs:
Dim qtApp ‘ Declare the Application object variable
Dim qtTest ‘ Declare a Test object variable
Dim qtResultsOpt ‘Declare a Run Results Options object variable
Set qtApp = CreateObject(”QuickTest.Application”) ‘ Create the Application object
qtApp.Launch ‘ Start QuickTest
qtApp.Visible = True ‘ Make the QuickTest application visible
qtApp.Open “C:\Documents and Settings\pwahi\Desktop\Google search“, True ‘ Open the test in read-only mode
‘ set run settings for the test
Set qtTest = qtApp.Test
qtTest.Run’ Run the test
WScript.StdOut.Write “Status is:” & qtTest.LastRunResults.Status ‘ Check the results of the test run
qtTest.Close ‘ Close the test
Set qtTest = Nothing ‘ Release the Test object
Set qtApp = Nothing ‘ Release the Application object
Now in order to execute QTP script from command line we have to execute the above created vbs file from command prompt which will in turn launch QTP, open the script, run it and will display the result in command prompt only. Open command prompt and write following code:
C:\Documents and Settings\pwahi\Desktop>cscript //nologo demo.vbs
And press enter
This command will execute the demo.vbs file which in turn launch QTP, open the script Google search, execute it and will display the result in QTP result file. We can also see the results in command prompt as shown below.
If the script passes the result is declared in command prompt as follows:
Status is: Passed
Info
http://www.qacampus.com
http://www.crestech.in
Software Testing
Australia
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment