Checking Operation Result

Applies to TestComplete 14.61, last modified on April 22, 2021

Operations used in keyword tests may return values. For instance, an operation that calls a method or property of some object returns the value, which the called method (or property) returns. Another example is the If … Then operation that returns True or False according to the condition, which the operation checks and which is specified by the operation’s parameters. To learn whether an operation returns any value, see the operation’s description in the Operation Reference section.

To use the operation’s result, specify the Last Operation Result value type for one of the parameters of the subsequent operation. This operation must be executed right after the operation, whose result you are going to use. For example, suppose that you have the Run Script Routine operation that calls a script function. Suppose also, that this script function returns a value and you need to process this value in your keyword test. For example, you need to post this value to the log. To perform this task, follow these steps:

  1. Add the Log Message operation to your keyword test. This operation will save the result value to the test log.

  2. On the first page of the ensuing wizard, click Next.

  3. On the Operation parameters page of the Log Message wizard, select the row of the MessageText parameter and click the ellipsis button in the Value column.

  4. In the ensuing Edit Parameter dialog, choose the Last Operation Result value in the Mode combo box and click OK:

    Properties of the Log Message Operation
  5. Click OK to close the Operation Parameters dialog and to save the changes.

  6. Important: change the position of the Log Message operation so that it is executed exactly after the Run Script Routine operation:

    Operations' order

Now, if you run the keyword test, the result of the Run Script Routine operation will be retrieved and passed to the Str parameter of the Log Message operation and then posted to the test log.

An important point here is that the result-processing operation is executed right after the operation that returns the result. No other operations, including Go to Label, must reside between them.

It is quite possible that you will need to execute the result-processing operation later, but not right after the operation that returns the result. In this case, you can use the Set Variable Value operation to save the result to a variable and then work with the variable’s value. Let’s modify our example a little. Suppose that for some reason the Log Message operation cannot be executed right after the Run Script Routine, so you need to store the result in a variable:

  1. In the Keyword Test editor, switch to the Variables page.

  2. Right-click within the editor and select New Item from the context menu. This will create a new local variable. Name this variable as MyVar1.

    Variables Page
  3. Switch to the Test Steps page of the Keyword Test editor. Click the Set Variable Value operation in the Statements category and then click somewhere within the keyword test to add this operation to the test.

    TestComplete will display the Operation Parameters dialog for the Set Variable Value operation.

  4. On the first page of the dialog, select the MyVar1 variable. Switch to the next page.

    Select the MyVar1 Variable
  5. On the next page, choose the Last Operation Result value in the Mode combo box:

    Select Last Operation Result

    Click Finish. The operation will be added to the keyword test.

  6. Important: change the position of the Set Variable Value operation in the test so that this operation will be executed right after the Run Script Routine:

    Operations' order
  7. Open the parameters of the Log Message operation for editing. In the Operation Parameters page of the Log Message wizard, select the MessageText parameter and click the ellipsis button in the Value column.

  8. In the ensuing Edit Parameter dialog, specify Variable in the Mode combo box and choose the MyVar1 variable in the Value combo box. Then click OK:

    Properties of the Log Message Operation

    Click OK to close the Operation Parameters dialog and to save the changes. The test looks as follows:

    Operations' order

Now, if you run the keyword test, the result of the Run Script Routine operation will be stored in the MyVar1 variable by the Set Variable Value operation and then the Log Message operation will post the variable’s value to the test log.

See Also

Keyword Tests
About Keyword Testing
Specifying Operation Parameters
Set Variable Value Operation
Debugging Tests

Highlight search results