Get Command Line Argument

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlw16
    New Member
    • Oct 2006
    • 2

    Get Command Line Argument

    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.Data Table.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.GetAssocia tedAddins method.
    '************** *************** *************** *************** *************** *************** *************** *************** *
    'Option Explicit
    Dim qtApp 'As QuickTest.Appli cation ' Declare the Application object variable
    Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
    Dim qtResultsOpt 'As QuickTest.RunRe sultsOptions ' Declare a Run Results Options object variable
    Dim qt_file 'As String

    Set qtApp = CreateObject("Q uickTest.Applic ation") ' 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.R un.CaptureForTe stResults = "OnError"
    qtApp.Options.R un.RunMode = "Fast"
    qtApp.Options.R un.ViewResults = False

    qtApp.Open "C:\Program Files\Mercury Interactive\Qui ckTest Professional\Te sts\tm_accts", True ' Open the test in read-only mode

    ' set run settings for the test
    Set qtTest = qtApp.Test
    qtTest.Settings .Run.IterationM ode = "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.Data Table.Import qt_file ' Import data from an external file provided by command line
    qtApp.Test.Data Table.ImportShe et qt_file, "Query", "Action1" ' Import a single sheet
    'qtApp.Test.Dat aTable.Import "C:\test.xl s" ' Import data from an external file
    'qtApp.Test.Dat aTable.ImportSh eet "C:\test.xl s", "Query", "Action1" ' Import a single sheet

    Set qtResultsOpt = CreateObject("Q uickTest.RunRes ultsOptions") ' Create the Run Results Options object
    qtResultsOpt.Re sultsLocation = "C:\temp\Result s" ' Set the results location

    qtTest.Run qtResultsOpt ' Run the test

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

    ' MsgBox qtTest.LastRunR esults.Status ' Check the results of the test run
    If qtTest.LastRunR esults.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
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by jlw16
    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.Data Table.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.GetAssocia tedAddins method.
    '************** *************** *************** *************** *************** *************** *************** *************** *
    'Option Explicit
    Dim qtApp 'As QuickTest.Appli cation ' Declare the Application object variable
    Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
    Dim qtResultsOpt 'As QuickTest.RunRe sultsOptions ' Declare a Run Results Options object variable
    Dim qt_file 'As String

    Set qtApp = CreateObject("Q uickTest.Applic ation") ' 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.R un.CaptureForTe stResults = "OnError"
    qtApp.Options.R un.RunMode = "Fast"
    qtApp.Options.R un.ViewResults = False

    qtApp.Open "C:\Program Files\Mercury Interactive\Qui ckTest Professional\Te sts\tm_accts", True ' Open the test in read-only mode

    ' set run settings for the test
    Set qtTest = qtApp.Test
    qtTest.Settings .Run.IterationM ode = "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.Data Table.Import qt_file ' Import data from an external file provided by command line
    qtApp.Test.Data Table.ImportShe et qt_file, "Query", "Action1" ' Import a single sheet
    'qtApp.Test.Dat aTable.Import "C:\test.xl s" ' Import data from an external file
    'qtApp.Test.Dat aTable.ImportSh eet "C:\test.xl s", "Query", "Action1" ' Import a single sheet

    Set qtResultsOpt = CreateObject("Q uickTest.RunRes ultsOptions") ' Create the Run Results Options object
    qtResultsOpt.Re sultsLocation = "C:\temp\Result s" ' Set the results location

    qtTest.Run qtResultsOpt ' Run the test

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

    ' MsgBox qtTest.LastRunR esults.Status ' Check the results of the test run
    If qtTest.LastRunR esults.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?

    Comment

    • jlw16
      New Member
      • Oct 2006
      • 2

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

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

      instead of the qt_file = Command line.

      Thanks!

      Comment

      • savitadjoshi
        New Member
        • May 2008
        • 1

        #4
        Hi,
        Where can I find help of all methods and properties of QuickTest application object. I want to manage everything throgh programming in QuickTest.

        Comment

        Working...