base » repeatUntil(steps,maxWaitMs)
Description
This command utilizes the execution of one or more subsequent commands to create a repeat-until-desired-result-reached behavior. In other words, using this command, one can achieve something like the following:
Start Loop
check condition: Is ConditionA reached?
if ConditionA reached, then exit loop
if ConditionA not yet reached, stay in the loop and
perform TaskA
perform TaskB
…
back to the beginning of the loop
One can perform a series of commands within the repeat-until execution, such as evaluate a SQL execution, wait for certain time, check for specific text or state of a web page or application.
A few things to note:
- Performing repetitions within a test scenario cause complication to the output format/file. As such, all command assigned for a repeat-until execution will not be updated in the corresponding Nexial output file. One can circumvent this issue by creating customize logs (show in Example below).
- First command MUST BE an assertion (validation). In other words, any command that starts with
assert
. It is this first command that will be used to evaluate the need to continue the repeat-until execution or to exit from it.FAIL
to such assertion means to continue the repeat-until loopPASS
to such assertion means to terminate the loop (i.e. the ‘until’ condition has reached) - therepeatUntil(steps,maxWaitMs)
command is considered asPASS
- All other commands (besides the first assertion command) within the repeat-until loop is expected to
PASS
- Failure in any of these commands (expect the first) will result in the termination of repeat-until loop - the
repeatUntil(steps,maxWaitMs)
command is considered asFAIL
- EXCEPT when
nexial.failFast
is set tofalse
. The repeat-until loop honors thenexial.failFast
system variable so that one can “collect-all-failures” rather than “fail-at-first-instance”. - To enforce the “fail-at-first-instance” requirement, either
-set JAVA_OPT=-Dnexial.failFast=true
on command line before running Nexial, OR - add to your datasheet:nexial.failFast | true
, OR - via command:base | save(var,value) | nexial.failFast | true
- Failure in any of these commands (expect the first) will result in the termination of repeat-until loop - the
- If one wish to limit the timespan such repeat-until execution, the second parameter
maxWaitMs
can be used. However, it must be a value greater than1000
(i.e. 1 second). Use-1
if time should not be considered as a constraint (ie. disable time tracking). This is a great way to simulate a time-out condition. - The use of verbose(text) will have no impact to the corresponding output file. However the output produced by this command can be observed in the console log.
- Thre are 3 System variable specificall related to this command:
nexial.repeatUntil.index
- to track the loop occurrence.nexial.repeatUntil.startTime
- to track the start time, in epoch, of arepeat-until
instance.nexial.repeatUntil.endTime
- to track the end time, in epoch, of arepeat-until
instance.
Parameters
- steps - this parameter specifies the number of subsequent (as in immediately following) commands to consider for the repeat-until execution.
- maxWaitMs - this parameter specifies the amount of time to wait before consider the repeat-until execution as
a failure (i.e. time out). Use
-1
to signify the willingness to wait forever.
Example
Here’s an example of how this command can be used:
Here, we have recruited 5 steps (Row 6 through Row 10) in the repeat-until execution. As stated, the first step
MUST be an assertion - assertEqual()
. The assertion is “make sure counter
equal to 20?”. Upon the successful validation of this assertion, the loop-until execution will exit (as SUCCESS).
We use -1
in the repeatUntil(steps,maxWaitMs)
command, which is keep looping until the first assertion command is
successful.
The rest of the commands are self-explanatory, and fairly inconsequential to the context of this page. Here’s the
outcome:
As stated earlier, there is no result or elapsed time for the steps utilized by the repeat-until execution.