To help simplify more complex scenarios with repeated sequences of steps, we’re happy to share two new ways to create loops in your UI tests:
Previously, looping through on-screen elements or array items required much more test setup, including snippets, custom find steps, and combining mabl variable syntax with loop indices. These new loop options reduce the manual setup required for handling dynamic data and lists.
Loop using elements
Loop through all elements matching a CSS query, and use a new runtime variable called {{@run.loop_locator}} to target the specific matching element for the current index. Use this setting to verify every row in a table, click on a set of checkboxes, or parse a multi-column grid.
Loop using elements is supported for browser tests only.
Try it out
To loop using elements, write a CSS query to identify matching elements.
Use {{@run.loop_locator}} to interact with the current element in a custom find step: click it, assert on it, or extract a value from it.
Loop using a variable array
Set the loop according to the number of items in an array-type variable. On each iteration, a new loop item variable, {{@run.loop_item}}, resolves to the array value at the current index. Use this loop setting to search for, interact with, or validate a list of items without using JavaScript or complex mabl variable syntax.
Loop using variable array is supported for both browser and mobile tests.
How it works
Extract an array of data from an API response or a JavaScript snippet and store it in a variable. Then set the loop to use the array variable.
For example, if you make an API request to get all the users in an account, you could store it in a variable called account_users, then set the loop to use the array variable account_users.
Access the array item at the current index using a new runtime variable called {{@run.loop_item}}.
If you are working with an array of objects, use dot notation inside the curly brackets to access specific properties. For example, if each item in the account_users array has an email property, you could assert the email addresses for all account users using the following syntax: {{@run.loop_item.email}}.