How to Specify Parameters for the Test Run

Applies to TestComplete 15.47, last modified on January 20, 2023

Each project has test items that specify the tests to be run and which order to run them in. When you add a test item to the project, you can specify parameters for the test that will be run by this test item. But the question always arises as to how to specify parameters for the entire test run?

The easiest way to do this is to create a small script or keyword test that will be run first and will initialize the desired parameters. However, this means you that you have to specify parameter values in your keyword test or script code, that is, you have to modify the test sources before running the test. If you do not want to modify the sources, use any of the solutions listed below.

  • You can set up a small text file with a parameter string in it, and have the initialization test read the parameters from there. But in this case, it has to interpret them itself.

  • You can use the InputBox routine to ask the tester for parameters. This routine is built into TestComplete and it is supported by all scripting languages -- JavaScript, JScript, Python, VBScript, DelphiScript, C#Script and C++Script. To call the routine from within keyword tests, you can use the Call Object Method or Run Code Snippet operation.

  • You can pass parameters via the TestComplete command line. To obtain the value of these command-line arguments, use the BuiltIn.ParamCount and BuiltIn.ParamStr functions. Use the Call Object Method operation to call those functions from a keyword test.

  • You can use project and project suite variables. The values of these variables depend on the machine where the test is run. In other words, the values of these variables differ from one tester’s computer to another. These variables depend on how their values are shared: project, project suite and network suite.

    Once a variable has been created, it appears in the Code Completion window under the Project > Variables or ProjectSuite > Variables node. To access existing variables in a test, use the Project.Variables.variable_name or ProjectSuite.Variables.variable_name syntax correspondingly. For instance the following code reads the value of a project variable MyExportFilePath:

    JavaScript, JScript

    function Main()
    {
      LoadDataFromFile(Project.Variables.MyExportFilePath);
      ...
    }

    Python

    def Main():
      LoadDataFromFile(Project.Variables.MyExportFilePath)
      ...

    VBScript

    Sub Main
      LoadDataFromFile Project.Variables.MyExportFilePath
      ...
    End Sub

    DelphiScript

    procedure Main;
    begin
      LoadDataFromFile(Project.Variables.MyExportFilePath);
      ...
    end;

    C++Script, C#Script

    function Main()
    {
      LoadDataFromFile(Project["Variables"]["MyExportFilePath"]);
      ...
    }

See Also

InputBox Method
ParamCount Method
ParamStr Method
Project And Project Suite Variables

Highlight search results