With loops, you can set up a sequence of test steps to repeat using a fixed number or a variable. This article explains how to work with loops in the mabl Trainer, including how to…
How to create a loop
In the mabl Trainer, take the following steps to create a loop:
- Click on + (Add step) > Create a flow.
- Give the flow a name. Optionally, you may also add parameters.
- Click on the Looping tab.
- Select Loop using a fixed number or Loop using a variable. The value must be a valid number between 2 and 500. You cannot set a flow to loop using a flow parameter.
- Click OK.
- With the Trainer cursor inside the Start flow and End flow steps, record the test steps that you would like to repeat in the loop.
Alternatively, you may convert an existing set of test steps into a loop. Create a loop, then drag and drop the Start flow and End flow steps so that they wrap around the test steps you want to repeat in the loop.
When you configure a looping value for a flow, the settings are not applied to other instances of the flow. We recommend using a naming convention in your workspace to identify flows that are intended to function as a loop.
How to access the loop index
Within a loop, mabl adds a special, read-only variable called
run.loop_index, which starts at 1. To access the loop index, use mabl variable syntax:
How to exit a loop early
To create a de facto while loop that exits the loop when a specific condition is met, follow these steps:
- Create a variable and assign it a number as a value.
- Create a flow that loops using the variable you just created.
- In the flow, add an IF step that asserts the conditions in which the loop should exit.
- In the IF step, add a variable step that creates a new variable with the same name as the looping variable, and set the value to 0.
- Add an ELSE step
- In the ELSE step, record the steps that the loop should do if the break conditions are not met.
In the example below, the variable
total is initialized to
500. In the loop, as soon as the number of checked checkboxes reaches five, the value of
total changes to
0. Updating the value of the looping variable causes the loop to exit early.
Exiting a loop early