In TestComplete, you can create a script routine with any number of parameters. You define script routine parameters in the script code.
For example, 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: You do not need to specify the parameter types in the script. By default, the type of parameters is Variant. It means that the parameters can hold any Variant-compatible value: string, integer, date, object, and so on.
In the routine code, you can work with routine parameters as you work with local script variables. For instance:
JavaScript, JScript
function MyRoutine(Param1, Param2, Param3)
{
// ...
// Post the Param1 parameter value to the test log
Log.Message("Message: " + aqConvert.VarToString(Param1));
// ...
}
Python
def MyRoutine(Param1, Param2, Param3):
# ...
# Post the Param1 parameter value to the test log
Log.Message("Message: " + aqConvert.VarToString(Param1))
# ...
VBScript
Sub MyRoutine(Param1, Param2, Param3)
' ...
' Post the Param1 parameter value to the test log
Call Log.Message("Message: " + aqConvert.VarToString(Param1))
' ...
End Sub
DelphiScript
procedure MyRoutine(Param1, Param2, Param3);
begin
// ...
// Post the Param1 parameter value to the test log
Log.Message('Message: ' + aqConvert.VarToString(Param1));
// ...
end;
C++Script, C#Script
function MyRoutine(Param1, Param2, Param3)
{
// ...
// Post the Param1 parameter value to the test log
Log["Message"]("Message: " + aqConvert["VarToString"](Param1));
// ...
}
To run a parameterized script routine
You cannot run parameterized script routines directly from the Code Editor. To run a parameterized routine, you must pass parameters to it. Thus, you can run parameterized routines in the following ways:
As a test item
-
Open the Execution Plan editor of your project. To do this, select View > Organize Tests from the TestComplete main menu.
-
In the Execution Plan editor, add a test item that will run your parameterized routine.
-
In the Parameters column of the created test item, click the ellipsis button and specify the desired parameter values in the resulting Test Parameters dialog:
-
Run the test item.
You can do this manually from the TestComplete UI by clicking Run Focused Item on the toolbar of the Execution Plan editor:
You can also run the entire project (manually, from the TestComplete UI, or automatically, from the TestComplete command line). The project will execute all its test items, including your parameterized routine. See Running Test Items.
From another routine
-
Create a routine that will call your parameterized routine.
-
Specify the desired parameter values to pass to your routine within parentheses.
-
Run the routine that calls your parameterized routine.
For example, in the code below, the Main
routine calls the parameterized MyRoutine
routine with the specified parameter values:
JavaScript, JScript
function Main()
{
// ...
MyRoutine("My String Parameter", 10, true);
// ...
}
function MyRoutine(Param1, Param2, Param3)
{
// ...
}
Python
def Main():
# ...
MyRoutine("My String Parameter", 10, True)
# ...
def MyRoutine(Param1, Param2, Param3):
# ...
VBScript
Sub Main
' ...
Call MyRoutine("My String Parameter", 10, True)
' ...
End Sub
Sub MyRoutine(Param1, Param2, Param3)
' ...
End Sub
DelphiScript
procedure MyRoutine(Param1, Param2, Param3);
begin
// ...
end;
procedure Main();
begin
// ...
MyRoutine('My String Parameter', 10, true);
// ...
end;
C++Script, C#Script
function Main()
{
// ...
MyRoutine("My String Parameter", 10, true);
// ...
}
function MyRoutine(Param1, Param2, Param3)
{
// ...
}
From a keyword test
-
In your project, create a keyword test that will call your parameterized routine.
-
Add a Run Script Routine or Run Test operation to the test.
-
Select your parameterized routine in the operation’s Select Test dialog.
-
In the resulting Operation Parameters dialog, specify the desired parameter values the operation will pass to your routine when running it:
-
Run the keyword test:
When calling a parameterized routine, instead of specifying hard-coded parameter values, you can specify variables that hold the needed values. See Parameterizing Tests Using Variables.