repeat

Repeat a block of commands a specified number of times.

The repeat command executes a sequence of commands multiple times, either for a fixed number of iterations or until a specific condition is met.

Parameters

To customize sequence execution when using the repeat command, you can use the following parameters:

Parameter
Type
Description

times

integer

The number of times to repeat the commands.

while

condition

A condition that must evaluate to true for the loop to continue. The loop terminates when the condition becomes false.

commands

list

The list of commands to execute during each iteration.

Usage examples

Repeat a specific number of times

To execute a set of commands a fixed number of times, use the times parameter.

- repeat:
    times: 3
    commands:
      - tapOn: Button
      - scroll

In the above example, the test will repeat the process of tapping on the button and scrolling three consecutive times.

Repeat while a condition is true

To execute commands as long as a condition is met, use the while parameter. The loop continues as long as the element with the text ValueX is not visible.

Repeat using a JavaScript expression

The while parameter also accepts a JavaScript expression. The loop continues as long as the expression evaluates to true.

Repeat with a maximum count and a condition

You can combine times and while to repeat commands until a condition is met, but for no more than a specified number of iterations. The loop stops when either the while condition becomes false or the times count is reached, whichever occurs first.

The following example taps a button while an element is not visible, but stops after 10 attempts regardless of the element's visibility.

Here’s another example that logs "Hello World" four times. The times: 4 limit ensures the loop stops even if the condition never becomes false. For example, if the counter were never incremented.

circle-check

Learn how to use conditions in your Flows.

Last updated