Cycles & Loops

Cycles & Loops

testRigor has support for executing commands until a certain condition is true. For example:
click "Next" until page contains stored value "previously generated id"
It can be used for going through pages in long lists or scrolling down until a certain text is visible, or a certain button is visible. By default the action will be executed up to 10 times, but you can extend the maximum number of times by adding “up to”:
click "Next" up to 12 times until page contains strictly button "Place order"

Note: The maximum amount of loops set by testRigor is 42.

Loops with scrolls

Loops are also used frequently when scrolling. Here are some of the commands that can be used:
scroll down until page contains "something"
scroll down on "element1" up to 10 times until page contains "element2" // scrolls on the position on the screen, not the element itself
scroll up/down on a "container"
Troubleshooting: Sometimes tR will treat some text elements inside the container as visible, although they’re not visible to the actual user. This refers especially to containers with a lot of text (e.g., terms of agreement) where you have to scroll down all the way to the bottom of the text before the buttons or checkboxes at the bottom are enabled. The way to handle this instance is the following:
scroll down until "I agree" is visible using OCR
scroll down until "I agree" is visible using OCR only

Loops with dynamic waits

A good practice is to make sure that dynamic waits are used as little as possible. However, sometimes you might need to use longer wait times for steps that take longer than the default wait timeouts.

Here’re some commands that can be used:
wait 5 sec until page contains "text"
wait 5 sec up to 12 times until page contains "text"

In this case, testRigor will check for the element to appear every 5 seconds (up to a minute total), and move to the next step once this criteria is satisfied.

Loops also work with reusable rules. For example, let’s consider a scenario where you need to click the Next button in a Google search until the page contains the result you’re looking for. You can create a reusable rule that we’ll call scroll and wait for this example using the following steps:
scroll down
wait 2 sec
The looped rule will look like this in the test:
scroll and wait until page contains "Social and Cultural Anthropology"

Keep in mind, the entire loop will happen before the check.

Test your knowledge

To execute commands repeatedly until a condition is met.
To generate random values.
To store data for later use.
To execute commands in a random order.
There is no limit.
wait 3 sec up to 10 times until page contains “Order Placed”
wait 10 times until page contains “Order Placed” every 3 sec
wait 3 sec up to 10 times till “Order Placed” appears
wait every 3 sec up to 10 times for”Order Placed” to appear