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 maximum number of times by adding “up to”:
click "Next" up to 12 times until page contains strictly button "Place order"

Loops with scrolls

Here’re some of the commands that can be used:
scroll down until page contains "something"
scroll down on "text" up to 10 times until page contains "text" // scrolls on the position on the screen, not the text 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. The workaround is to use the following commands:
  • Click using OCR (not OCR only)
  • Click using JavaScript
  • Use manual scroll (drag the scroll bar with the mouse, or click the down arrow until the element 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 if you know that your platform is slow-ish.

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 Google search until the page contains the result you’re looking for. You can create a reusable rule, let’s call it scroll and wait:
scroll down
wait 2 sec
Next, the test will look like this:
scroll and wait until page contains "Social and Cultural Anthropology"

Keep in mind, the entire loop should happen before the check, otherwise testRigor won’t detect it (for example, if the loop scrolls through the book, and then scrolls past it).

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.
The check should always happen before the loop.
The loop should happen after the check.
The loop should happen before the check.
The order of loops and checks doesn’t matter.
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 until page has “Order Placed”
[wpcode id=”1112380″ answers=”1;3;1″ page=”Cycles / Loops” numoffields=”3″]