Repeat until true
Quite similar to the previously described iterate container this repeating container will execute its actions in a loop according to an ending condition. The condition describes a Boolean expression using the operators as described in the previous chapter.
Note The loop continues its work until the provided condition evaluates to true . It is very important to notice that the repeat loop will execute the actions before evaluating the condition. This means the actions get executed 1-n times.
XML DSL
<testcase name="iterateTest">
<actions>
<repeat-until-true index="i" condition="(i = 3) or (i = 5)">
<echo>
<message>index is: ${i}</message>
</echo>
</repeat-until-true>
</actions>
</testcase>
Java DSL designer and runner
@CitrusTest
public void repeatTest() {
repeat().until("(i gt 5) or (i = 3)").index("i"))
.actions(
echo("index is: ${i}")
);
}
As you can see the repeat container is only executed when the iterating condition expression evaluates to false . By the time the condition is true execution is discontinued. You can use basic logical operators such as and, or and so on.
A more powerful way is given by Hamcrest matchers that are directly supported in condition expressions.
XML DSL
<testcase name="iterateTest">
<actions>
<repeat-until-true index="i" condition="@assertThat(anyOf(is(3), is(5))@">
<echo>
<message>index is: ${i}</message>
</echo>
</repeat-until-true>
</actions>
</testcase>
Java DSL designer and runner
@CitrusTest
public void repeatTest() {
repeat().until(anyOf(is(3), is(5)).index("i"))
.actions(
echo("index is: ${i}")
);
}
The Hamcrest matcher usage simplifies the reading a lot. And it empowers you to combine more complex condition expressions. So I personally prefer this syntax.