Parameterizing Script Routines

Applies to TestComplete 12.60, last modified on September 17, 2018

TestComplete allows you to create a script routine with any number of parameters. You define script routine parameters in the script code. Suppose you want to create a routine called MyRoutine, that has three parameters: Param1 (string), Param2 (integer) and Param3 (boolean). To do this, use the following script code:

JavaScript, JScript

function MyRoutine(Param1, Param2, Param3)
{
  ...
  ...
}

Python

def MyRoutine(Param1, Param2, Param3):
  ...
  ...

VBScript

Sub MyRoutine(Param1, Param2, Param3)
  ...
  ...
End Sub

DelphiScript

procedure MyRoutine(Param1, Param2, Param3);
begin
  ...
  ...
end;

C++Script, C#Script

function MyRoutine(Param1, Param2, Param3)
{
  ...
  ...
}

Note that you do not need to specify the parameter types in the script. By default, the type of defined parameters is Variant. It means that the parameters can hold any Variant-compatible value: string, integer, date, object, and so on.

Within the routine code you work with routine parameters like you work with local script variables. For instance:

JavaScript, JScript

function MyRoutine(Param1, Param2, Param3)
{
  ...
  // Passes the Param1 parameter to the Log.Message method
  Log.Message("Message: " + Param1);
  ...
}

Python

def MyRoutine(Param1, Param2, Param3):
  ...
  # Passes the Param1 parameter to the Log.Message method
  Log.Message("Message: " + Param1)
  ...

VBScript

Sub MyRoutine(Param1, Param2, Param3)
  ...
  ' Passes the Param1 parameter to the Log.Message method
  Call Log.Message("Message: " + Param1)
  ...
End Sub

DelphiScript

procedure MyRoutine(Param1, Param2, Param3);
begin
  ...
  // Passes the Param1 parameter to the Log.Message method
  Log.Message('Message: ' + Param1);
  ...
end;

C++Script, C#Script

function MyRoutine(Param1, Param2, Param3)
{
  ...
  // Passes the Param1 parameter to the Log.Message method
   Log["Message"]("Message: " + Param1);
  ...
}

You can execute a script routine as a test item, or you may call it from another script routine or from a keyword test. The way you call the routine affects the way you pass the parameters to it:

  • To run a script routine as a test item, you create a new item in the Test Items page of the project editor. To specify the routine parameters:

    • First, specify the routine in the Test column.

    • Then click the ellipsis button of the Parameters cell and set the desired parameter values in the ensuing Test Parameters dialog.

    When TestComplete executes this test item it will pass the values you specified in the dialog to your script code.

  • If you call a script routine from another script routine, then simply specify the parameter values in parentheses. For example, to call the MyRoutine routine with specified parameters values, you can use the following script code:

    JavaScript, JScript

    function TestRoutine()
    {
      ...
      MyRoutine("My String Parameter", 10, True);
      ...
    }

    Python

    def TestRoutine():
      ...
      MyRoutine("My String Parameter", 10, True)
      ...

    VBScript

    Sub TestRoutine
      ...
      Call MyRoutine("My String Parameter", 10, True)
      ...
    End Sub

    DelphiScript

    procedure TestRoutine;
    begin
      ...
      MyRoutine('My String Parameter', 10, True);
      ...
    end;

    C++Script, C#Script

    function TestRoutine()
    {
      ...
      MyRoutine("My String Parameter", 10, True);
      ...
    }

  • To call the script routine with parameters from a keyword test, use the Run Script Routine or Run Test operation. When adding the operations to the test, you can specify the values of the script routine parameters in the Operation Parameters dialog.

Note: Instead of specifying hard-coded parameters values, you can also specify variables that hold these values (see Parameterizing Tests Using Variables).

See Also

Parameterizing Tests
Parameterizing Keyword Tests

Highlight search results