33.1 Procedure with a Variable

Take a look at the last test step "Check final price" in our two test cases.

Two almost identical test steps
Figure 33.1:  Two almost identical test steps

The same step is executed, but with different data. Even if it is just a single step, it makes sense to turn it into a procedure. We might later decide to convert the hard-coded values 13.349,00 € and 12.734,00 € to another format so that the check on the "Final price" field works for other currencies as well. Implementing such logic twice would definitely not be sensible.

Procedure with hard-coded value
Figure 33.2:  Procedure with hard-coded value

As expected, the Check text node is inside the procedure. However, it is only valid for a single price, namely 13.349,00 €. Since we also want to use the same procedure for the second test case, we need to replace the price with a variable. The value of this variable should then be passed when calling the procedure.

In the next example we will add a parameter with a default value in the procedure node. Default values are often used when the corresponding parameter would receive that value in most procedure calls. Then you don't need to specify the default value every time and can rely on the value defined in the procedure node. Although this does not apply to the price parameter, we can use it here to show how a default value works and how it can be overridden with another value when needed.

First, let’s add a variable with a default value:

Details of a procedure node
Figure 33.3:  Details of a procedure node

In the next step, we replace the value of the Text attribute of the Check text node with a reference to the variable.

Note Variable syntax: When working with variables it is important to understand that in some places you tell QF-Test what the name of a variable is and in others you tell QF-Test to access the value of a variable.

In the example above, QF-Test is informed of the variable name in the name column of the default values table. In that case you only needed to enter price.

In the Text attribute of the Check text node, the value of the variable should be used. In QF-Test this is done by putting the variable name in $(), here $(preis). If you do not wrap the variable name in $(), QF-Test would compare the price with the literal string price.

'Check text' node
Figure 33.4:  'Check text' node

The test case should run without errors.