Control flow

In this section you will learn how to run steps only when a condition is met, or repeat them.

JavaScript expressions

Conditions are JavaScript expressions. Store a value first — with store, store text, store value or execute script — then test it in a control flow command, referring to the variable as ${name}.

You can also write the expression directly in the control flow command, for example ${count} > 3.

Available commands

Control flow commands open and close a block of steps:

  • if, else if, else, end
  • times, end
  • do, repeat if
  • while, end
  • for each, end

Conditional branching

if

Opens a conditional block. Its Target is the expression to evaluate. When it is true, the steps that follow run up to the next else if, else or end; otherwise Pulse jumps to the next of these commands.

else if

Used inside an if block. Like if, its Target is an expression: when true, the steps that follow run; otherwise Pulse jumps to the next else if, else or end.

else

The last branch of an if block, run when no earlier condition was true.

end

Closes the block. A block without its end is incomplete, and Pulse names the step at fault when you run the test.

Command Target Value
execute script return “c” myVar
if ${myVar} === “a”
execute script return “a” output
else if ${myVar} === “b”
execute script return “b” output
else
execute script return “c” output
end
assert output c

Loops

times

Repeats the block a fixed number of times, given as Target. Close it with end.

Command Target Value
times 3
click id=next
end

do and repeat if

Runs the block once, then evaluates the expression of repeat if (its Target): while it is true, Pulse goes back to do.

while

Evaluates its expression (Target) first, and runs the block up to end as long as it is true.

Both repeat if and while stop after 1000 iterations to protect you from an endless loop. Set another limit in their Value field.

Command Target Value
execute script return 1 i
while ${i} < 4
execute script return ${i} + 1 i
end

for each

Iterates over a JavaScript array. Target is the variable that holds the array, Value the name of the variable that receives each entry in turn.

Command Target Value
execute script return [“one”, “two”, “three”] items
for each items item
echo ${item}
end

Nesting

Blocks can be nested: an if inside a while, a times inside an if, and so on. Close the inner block before the outer one.

See also

  • Commands — the control flow commands in the reference
  • Arguments — conditional expressions, loop limits and variables

Translations