By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

Get Command Line Argument

P: 2
Hello,
I’m trying to use my vbs script to get a command line argument for a file which will need to be opened through QuickTestPro. Below are the commands I’m using:

Dim qt_file 'As String -> If I don’t comment out the As String, I get an “Expected end of statement” error – is this correct??
qt_file = Command -> This doesn’t appear to be correct – when I echo out qt_file it’s null
qtApp.Test.DataTable.Import qt_file ' Import data from an external file provided by command line -> This command should open the file in QTP that was provided at the command line. If I set qt_file to a shared drive file it works fine.

Can someone please help me w/ the correct syntax? The full program is below:

'************************************************* ************************************************** *********************
'Description:
'
'This example opens a test, configures run options and settings,
'runs the test, and then checks the results of the test run.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'When QuickTest opens, it loads the add-ins required for the test.
'For more information, see the example for the Test.GetAssociatedAddins method.
'************************************************* ************************************************** *********************
'Option Explicit
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
Dim qt_file 'As String

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible
'qt_file = "L:\SCM\TM\test.xls"
qt_file = Command()
MsgBox "Command file: " & qt_file

' Set QuickTest run options
qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

qtApp.Open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\tm_accts", True ' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngAll"
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

' Import data to the design-time Data Table and then add new data
qtApp.Test.DataTable.Import qt_file ' Import data from an external file provided by command line
qtApp.Test.DataTable.ImportSheet qt_file, "Query", "Action1" ' Import a single sheet
'qtApp.Test.DataTable.Import "C:\test.xls" ' Import data from an external file
'qtApp.Test.DataTable.ImportSheet "C:\test.xls", "Query", "Action1" ' Import a single sheet

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\temp\Results" ' Set the results location

qtTest.Run qtResultsOpt ' Run the test

' Save the Run-time Data Table
qtApp.Test.LastRunResults.DataTable.Export "C:\Runtime.xls" ' Save the run-time Data Table to a file

' MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
If qtTest.LastRunResults.Status="Failed" then
WScript.stdout.WriteLine "Test failed"
Else
WScript.stdout.WriteLine "Test successful"
End if

qtTest.Close ' Close the test
qtApp.quit ' Close the app

Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
Oct 17 '06 #1
Share this Question
Share on Google+
3 Replies


100+
P: 1,646
Hello,
I’m trying to use my vbs script to get a command line argument for a file which will need to be opened through QuickTestPro. Below are the commands I’m using:

Dim qt_file 'As String -> If I don’t comment out the As String, I get an “Expected end of statement” error – is this correct??
qt_file = Command -> This doesn’t appear to be correct – when I echo out qt_file it’s null
qtApp.Test.DataTable.Import qt_file ' Import data from an external file provided by command line -> This command should open the file in QTP that was provided at the command line. If I set qt_file to a shared drive file it works fine.

Can someone please help me w/ the correct syntax? The full program is below:

'************************************************* ************************************************** *********************
'Description:
'
'This example opens a test, configures run options and settings,
'runs the test, and then checks the results of the test run.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'When QuickTest opens, it loads the add-ins required for the test.
'For more information, see the example for the Test.GetAssociatedAddins method.
'************************************************* ************************************************** *********************
'Option Explicit
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
Dim qt_file 'As String

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible
'qt_file = "L:\SCM\TM\test.xls"
qt_file = Command()
MsgBox "Command file: " & qt_file

' Set QuickTest run options
qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

qtApp.Open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\tm_accts", True ' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngAll"
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

' Import data to the design-time Data Table and then add new data
qtApp.Test.DataTable.Import qt_file ' Import data from an external file provided by command line
qtApp.Test.DataTable.ImportSheet qt_file, "Query", "Action1" ' Import a single sheet
'qtApp.Test.DataTable.Import "C:\test.xls" ' Import data from an external file
'qtApp.Test.DataTable.ImportSheet "C:\test.xls", "Query", "Action1" ' Import a single sheet

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\temp\Results" ' Set the results location

qtTest.Run qtResultsOpt ' Run the test

' Save the Run-time Data Table
qtApp.Test.LastRunResults.DataTable.Export "C:\Runtime.xls" ' Save the run-time Data Table to a file

' MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
If qtTest.LastRunResults.Status="Failed" then
WScript.stdout.WriteLine "Test failed"
Else
WScript.stdout.WriteLine "Test successful"
End if

qtTest.Close ' Close the test
qtApp.quit ' Close the app

Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
Is this code that you wrote yourself?
Oct 17 '06 #2

P: 2
No, this was code provided by Quick Test Pro that I modified. I think I got it working though using:

qt_file = WScript.Arguments.Item(0)
Wscript.Echo "File Path: " & qt_file

instead of the qt_file = Command line.

Thanks!
Oct 17 '06 #3

P: 1
Hi,
Where can I find help of all methods and properties of QuickTest application object. I want to manage everything throgh programming in QuickTest.
May 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.