Using conditional statements and loops in TestCases
In Tosca, you can define IF, DO and WHILE statements if you would like to run TestSteps with branches or repeatedly. These statements can be applied to any nested structures.
If the number of repetitions for a TestStep is known beforehand, use the property Repetition of a TestStepFolder as described in chapter "Running TestSteps repeatedly - Repetitions".
Conditional statements and loops can be created via the context menu of TestCases or TestStep folders or via the option Create Object in the dynamic menu TestCases:
-
IF Statement
-
DO Statement
-
WHILE Statement
A Conditions object is created for all three options. In this folder you define the condition that must be fulfilled so that the next step can be taken. The next step depends on the type of the statement.
Test results of conditions do not affect the total result of the test execution. |
Statement options
Creating IF-THEN statements
When you create IF statements, Tosca will automatically create a THEN statement along with the Conditions object. You can also create an ELSE statement via the context menu of IF statements if required, or by left-clicking the IF statement and selecting Create Object->ELSE Statement from the dynamic menu TestCases.
If the condition is fulfilled, the TestSteps are executed once in the THEN statement. If the condition is not fulfilled however, the TestSteps are run once in the ELSE statement.
Order of conditions:
-
IF
-
Condition (within the IF statement)
-
THEN (within the IF statement)
-
ELSE (optional)
IF-THEN-ELSE Statement The test result looks as follows:
Test result |
Creating DO statements
When you create DO statements, Tosca will automatically create a Loop object along with the Conditions object.
TestSteps within the Loop object are run repeatedly until the condition is no longer fulfilled. The result of the last repetition is thus negative.
DO statements contain the property MaximumRepetitions in order to avoid infinite loops. The Value column shows the maximum number of attempts for a TestStep to be run. The default value is set to 30.
Order of conditions:
-
DO
-
Loop (within the DO statement)
-
Condition (within the DO statement)
Do statement The test result looks as follows:
Test result for the DO statement |
Creating WHILE statements
When you create WHILE statements, Tosca will automatically create a Loop object along with the Conditions object.
If the condition is fulfilled, TestSteps within the Loop object are run repeatedly until the condition is no longer fulfilled. The result of the last repetition is thus negative.
WHILE statements contain the property MaximumRepetitions in order to avoid infinite loops. The Value column shows the maximum number of attempts for a TestStep to be run. The default value is set to 30 (see Illustration "MaximumRepetitions property").
Order of conditions:
-
WHILE
-
Condition (within the WHILE statement)
-
Loop (within the WHILE statement)
WHILE statement The test result looks as follows:
Test result for the WHILE statement |