About test parameters
Operation parameters of recorded keyword tests hold constant, hard-coded values:
These values make a keyword test a “static” test that always uses the same set of testing data and always works in the same predefined manner. Sometimes, it is necessary to parameterize a keyword test: replace these static values with external values. This lets you use tests in a more flexible manner, because you can re-use the same test to simulate user input for different test data.
To pass external values to keyword tests, you use the keyword test parameters. These parameters are analogues to the parameters of test items or parameters of script routines.
You define the test parameters on the Parameters page of the Keyword Test editor or using the Add Parameter wizard.
Test parameters are accessible from any operation of the test, but they are not accessible from other tests.
Create test parameters
Using the Add Parameter wizard
-
Click Add Parameter on the toolbar of the Keyword Test editor. The Add Parameter wizard will appear.
-
On the first page of the wizard, specify the parameter properties needed for parameter creation:
-
In the Name edit box, specify the parameter name.
Note: The parameter name must match the naming rules of the scripting language used in your project. The easiest way to do this is to specify a name that only consists of alphanumeric or underscore characters and starts with a letter. -
In the Type box, specify the parameter’s type.
-
In the Description edit box, enter any descriptive text related to the parameter.
-
-
Click Next to specify the default value to the parameter. Finish will generate the parameter that will not have the default value.
-
On the second page, specify the value which the parameter will have by default. The values that will be used for the test run are specified in the script code, or in the Execution Plan editor of the project, or in the Keyword Test editor (see below).
-
Click OK to close the dialog and add a new parameter to a keyword test. Cancel will close the dialog without performing any actions.
The created parameter will be added to the Parameters page of the test automatically. Open your keyword test and switch to the Parameters tab at the bottom of the test editor:
The Parameters page contains information about existing parameters: name, data type, default value and description. For detailed information about the columns, see description of the page.
Using the Parameters page
-
Press the Add Parameter button on the page’s toolbar or right-click somewhere within the page and choose Add Parameter from the context menu.
-
Then you can specify the parameter’s name, type, default value and description.
Notes:
-
The parameter name must be a valid script identifier.
-
The order of parameters on the page is important, because it specifies the order, in which the parameters must be specified when the keyword test is executed from scripts (see below).
To change a parameter's position, you can either use the Move Up and Move Down buttons on the page’s toolbar or right-click the parameter on the page and then choose Move Up or Move Down from the context menu.
-
A parameter may have a default value. In this case, you do not have to specify the parameter’s value for each test run.
In the parameters list, the parameters that have default values must follow the parameters that do not have default values. So, if you define a default value for a parameter, you should position this parameter after the parameters that do not have default values.
On the Parameters page, you can also modify and delete parameters.
Parameter data types
A test parameter can have one of the following data types:
- String - Use this type for parameters that will contain characters and strings (including multi-line text).
- Integer - Use this type for parameters that will contain integer values.
- Double - Use this type for parameters that will contain floating-point values and dates.
- Boolean - Use this type for parameters that will contain True or False.
- Object - Use this type for parameters that store object references, for instance, references to the process or window objects. These parameters can have Null or Unassigned default values.
TestComplete checks the parameter type when you specify the parameter value in scripts. See the next section for details.
Replace hard-coded values of the operation with test parameters
To parameterize your tests, that is, to replace the operation's hard-coded values captured during test recording with created parameters:
-
Select the desired operation in your test, click somewhere within its Value column, and then click the ellipsis button.
-
Select the desired operation parameter in the Operation Parameters dialog.
-
Select Test Parameter in the Mode column of the dialog.
-
Choose the desired test parameter in the Value column.
-
Press Enter to confirm the change.
Now, when executing the operation, TestComplete will pass the value of the specified test parameter to the operation parameter.
Call a parameterized test with needed parameter values
If a keyword test has required parameters (parameters without default values), you can run it:
As a test item
-
Add an item for the test to the Execution Plan editor of your project.
-
Click the ellipsis button in the Parameters column.
-
In the resulting Test Parameters dialog, specify values for the test parameters.
Note: When you are creating a project test item that will use your keyword test, default values of test parameters are copied to the test item’s settings. If you then modify parameter values in the Keyword Test editor, the changes will not affect the test item. To change the test parameters, you have to modify the test item’s properties in the Execution Plan editor.
From another keyword test
To run a parameterized keyword test (“callee”) from another keyword test (“caller”), you use the Run Keyword Test or Run Test operations:
-
Add any of these operations to the “caller” test.
-
In the resulting Operation Parameters dialog, assign values to “callee” test parameters.
To modify parameters of a “callee” test already added to another test:
- Select the operation in the test.
- Select the Value cell and then either click within the cell or press F2. This will activate the in-place editor.
- Click the ellipsis button of the editor. This will invoke the Operation Parameters dialog, where you can specify the desired parameters’ values.
- To save the changes, close the dialog with the OK button and press Enter in the in-place editor to confirm the change.
From a script
-
To run a keyword test from a script, use the
KeywordTests.<KeywordTest_Name>.Run
method:KeywordTests.KeywordTest1.Run()
-
Specify the test’s parameters as the method’s parameters.
Suppose, you have a keyword test KeywordTest1 that has three parameters: Param1 (string), Param2 (integer) and Param3 (boolean). To specify the parameters and run the test, you can use the following script code:
JavaScript, JScript
KeywordTests.KeywordTest1.Run("My String Parameter", 10, true);
Python
KeywordTests.KeywordTest1.Run("My String Parameter", 10, true)
VBScript
Call KeywordTests.KeywordTest1.Run("My String Parameter", 10, True)
DelphiScript
KeywordTests.KeywordTest1.Run('My String Parameter', 10, True)
C++Script, C#Script
KeywordTests["KeywordTest1"]["Run"]("My String Parameter", 10, true);
When the test run starts, the test engine checks whether the types of the specified values are compatible with the parameters’ types. If not, TestComplete attempts to typecast the value to the parameter’s type. If this attempt fails, an error occurs.
A typical example that illustrates this statement is an assignment of string values to integer parameters. Suppose, you have a parameter of the integer type. If you assign the string "77" to it, this value will be converted to the number 77. However, if you attempt to assign the string "qwerty", the assignment will fail and an error will occur.
When typecasting string values to numerical ones, TestComplete implies that the string contains the numbers in decimal format. Hexadecimal, octal and binary formats are not supported.
You can modify the value of a keyword test parameter just from the corresponding keyword test. For this purpose, you can use the Parameters
object. This object has properties that provide access to individual parameters of the desired keyword test.
You can access keyword test parameters using the Parameters object only from the corresponding keyword test. You cannot access them from another keyword test or script. |
See Also
Keyword Tests
Keyword Tests
Keyword Test Editor - Parameters Page