How to execute a qtp script from command prompt?

It is very much possible to launch a QTP test from Command prompt and then run it. The script to open QTP and then load the test into QTP and run the test is given in the "Quick Test Automation reference" file which is given in the Documentation Folder.



The path to get the file and the code is "C:Program FilesMercury InteractiveQuickTest ProfessionalhelpAutomationObjectModel.chm"

I have taken this script from this file and changed the path of my test to be loaded and saved the file as a .vbs and executed it from the command prompt.

The script is given below for quick reference

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' 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

' Set QuickTest run options


qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"

qtApp.Options.Run.ViewResults = False
qtApp.Open "E:\Test Scripts\actiTIME FunctionCalls Script", True ' Open the test in read-only mode


' set run settings for the test


Set qtTest = qtApp.Test

qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4
qtTest.Settings.Run.StartIteration = 2
qtTest.Settings.Run.EndIteration = 4
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object


qtResultsOpt.ResultsLocation = "E:\Test Scripts\actiTIME FunctionCalls Script\Res1" ' Set the results location
qtTest.Run qtResultsOpt ' Run the test

MsgBox qtTest.LastRunResults.Status ' Check the results of the test run

qtTest.Close ' Close the test

Set qtResultsOpt = Nothing ' Release the Run Results Options object

Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object


For this you should have created a test with some actions in QTP and saved it then you need to specify the path of the test correctly at qtapp.Open

Save this file in a desired location with a .vbs extension.

Launch command prompt by going to run and type cmd and click enter.

The command prompt is visible. Since i store this .vbs file in E drive i have changed the directory in command prompt to E drive

C:\>E: and press enter

E:\> "This will be displayed" now enter the vbs file and click enter

E:\>testrun.vbs and clicked enter

Now the QTP will automatically launch load the specified test and runs it and gives you a message box prompt saying passed after the test is completed.

1 comments:

Anonymous said...

Hi Thanks very for sharing this post. This is very helpful. Just wondering if i will want to print the result via command prompt instead of the msg box what should i do?

Post a Comment

/* Tynt Insight tracker ----------------------------------------------- */