Keyword Test Parameters

Applies to TestComplete 14.0, last modified on January 23, 2019

This topic provides information about parameters of keyword tests. It contains the following sections:

About Test Parameters

Operation parameters of recorded keyword tests hold constant 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 with one or more external parameters. This lets you create and 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.

Defining Test Parameters

You can create parameters of keyword tests using the Add Parameter wizard or Parameters page of the Keyword Test editor.

To add a new parameter to a keyword test using the Add Parameter wizard:

  • Click the Add Parameter button 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 Test Items page of the project editor, 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.

After creating a parameter using the wizard, it will appear on the Parameters page of the Keyword Test editor. To display the page, open your keyword test for editing and select Parameters at the bottom of the editor.

The Parameters page is a table that contains information about existing parameters. The table columns display the parameters’s name, data type, default value and description. For detailed information about the columns, see description of the page.

To add a new parameter to a keyword test 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.

To modify and delete keyword test parameters, use the Parameters page.

Parameters’ Data Types

A test parameters variable 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.

Setting and Modifying Parameter Values

If a keyword test has required parameters, it can be executed as a test item, it can be executed from scripts or it can be run from another keyword test. The way you specify parameters depends on the way, in which the test is run.

  • If the test is run as a test item

    If you are going to run the test as a test item, then you add a node for the test to the test items tree on the Test Items page of the project editor. This page has the Parameters column that displays information about test parameters. To specify the parameters of your keyword test, click the ellipsis button of the Parameters column. This will invoke the Test Parameters dialog, where you can enter the desired 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 on the Test Items page.
  • If the test is run from another keyword test

    To run a keyword test (“callee”) from another keyword test (“caller”), you use the Run Keyword Test or Run Test operations. When you add these operations to the “caller” test, TestComplete displays the Operation Parameters dialog in which you can assign values to parameters of the “callee” test.

    If these operation are already added to the test, then to modify the parameters:

    • Select the operation in the test area.
    • 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.
  • If the test is run from a script

    To run a keyword test from a script, you use the Run method of the KeywordTest object which corresponds to your test, for instance:

    KeywordTests.KeywordTest1.Run()

    TestComplete forms the parameter list of this method automatically according to the list of test parameters. So, the parameters of the test “become” the method’s parameters. To specify them, you simply specify the method 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 is started, 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.

Using Test Parameters to Specify Operation Parameters

You use test parameters to specify operation parameters. To do this:

  • Open the desired operation for editing.

  • 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.

See Also

Keyword Tests
Keyword Testing - Overview
Keyword Test Editor - Parameters Page

Highlight search results