Loops are a step or a sequence of steps that will be repeated continually until a certain condition is met.
Loops are useful for several different scenarios. For instance, it's commonly necessary to scroll through very long pages until a certain text is visible or a certain button is visible.
In testRigor, we trigger a loop with the keyword
An example of this would look like the following:
scroll down until page contains "Submit" until page contains stored value "previously generated id"
Another common example is when we need to navigate through a list or table that may span multiple pages. If we wanted to find the name "Tom" from a long list of 10 pages, assuming we button to go to the next page on the list is called
Next, we could use the following:
click "Next" until page contains "Tom"
By default, the action will be executed up to 10 times, but you can extend the number of times by adding
up to and the maximum number of times the action should be repeated:
click "Next" up to 12 times until page contains "Tom"
Loops with Reusable Rules
Reusable rules can also be used in loops. You may need to group certain actions to be used in a loop, or there may be certain actions that are not currently supported in a loop. By putting that sequence of actions or the unsupported action into a rule, we can force it to loop.
An example of a command that is not currently supported in a loop is
go back. However, if you use it as a single line in a reusable rule and name the rule something different from the step itself (for instance
go back rule), loops will work.
go back until page contains "Welcome to homepage!"
Correct example (given the rule is created):
go back rule until page contains "Welcome to homepage!"
IMPORTANT NOTE: The maximum amounts of time testRigor can execute a loop is 42.
Reference link: For more info about Loops in testRigor, go here.