Stop Timer
The
XML DSL
<testcase name="timerTest">
<actions>
<timer id="forkedTimer" fork="true">
<sleep milliseconds="50" />
</timer>
<timer fork="true">
<sleep milliseconds="50" />
</timer>
<timer repeatCount="5">
<sleep milliseconds="50" />
</timer>
<stop-timer timerId="forkedTimer" />
</actions>
<finally>
<stop-timer />
</finally>
</testcase>
Java DSL designer and runner
@CitrusTest
public void timerTest() {
timer()
.timerId("forkedTimer")
.fork(true)
.actions(sleep(50L)
);
timer()
.fork(true)
.actions(sleep(50L)
);
timer()
.repeatCount(5)
.actions(sleep(50L));
stopTimer("forkedTimer")
doFinally().actions(
stopTimer()
);
}
In the above example 3 timers are started, the first 2 in the background and the third in the test execution thread. Timer #3 has a repeatCount set to 5 so it will terminate automatically after 5 runs. Timer #1 and #2 however have no repeatCount set so they will execute until they are told to stop.
Timer #1 is stopped explicitly using the first stopTimer action. Here the stopTimer action includes the name of the timer to stop. This is convenient when you wish to terminate a specific timer. However since no timerId was set for timer #2, you can terminate this (and all other timers) using the 'stopTimer' action with no explicit timerId set.