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:
-
Add the Log Message operation to your keyword test. This operation will save the result value to the test log.
-
On the first page of the ensuing wizard, click Next.
-
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.
-
In the ensuing Edit Parameter dialog, choose the Last Operation Result value in the Mode combo box and click OK:
-
Click OK to close the Operation Parameters dialog and to save the changes.
-
Important: change the position of the Log Message operation so that it is executed exactly after the Run Script Routine operation:
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:
-
In the Keyword Test editor, switch to the Variables page.
-
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.
-
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.
-
On the first page of the dialog, select the MyVar1 variable. Switch to the next page.
-
On the next page, choose the Last Operation Result value in the Mode combo box:
Click Finish. The operation will be added to the keyword test.
-
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:
-
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.
-
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:
Click OK to close the Operation Parameters dialog and to save the changes. The test looks as follows:
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
Keyword Testing - Overview
Specifying Operation Parameters
Set Variable Value Operation
Debugging Tests