mabl now supports while loops for browser tests! Previously, loops required a count: a fixed number, a variable, the length of an array, or the number of matching elements on the page. If you wanted to loop a sequence of steps based on a condition, such as clicking "Load more" until it disappeared or draining a queue, you had to set up a workaround to exit the loop early. Now you can add a native while loop in any testing scenario where a loop should repeat until a condition is met.
With while loops, the flow can repeat for as long as the condition holds, after which the test moves on. The condition uses the same assertion editor you already use in the Trainer, so it can check:
- UI changes on the page: repeat an action based on dynamic page state, such as paging through a table until the "Next" button is not present.
- Changes in dynamic data: evaluate data from dynamic variables in each iteration until a target condition is met. Use variables generated from page elements, JavaScript, API and database query responses.
While loops are supported for browser tests only.
Try it out
Update to the latest version of the mabl Desktop app, then take the following steps:
- In the Trainer, edit an existing loop or create a new while loop: + (Add step) > Loops > While loop.
- On the Condition tab, choose what to watch.
- Element selector - type a locator that matches the element you want to evaluate.
- Variable - select an existing variable in your test
- Define the conditions under which the element or variable should continue looping. For example, loop as long as the "Next" button is present, or loop as long as the value of the variable
apiCursordoes not equalnull. - You may optionally set an Iteration limit in the Looping tab. If a loop instead reaches the limit while the condition is still true, the step fails because the loop never finished the work it was asked to do.
- Click OK.
- With the Trainer cursor inside the Start flow and End flow steps, record the steps that you would like to repeat in the loop.
Loops are capped at 500 iterations whether or not you set a limit.