Ultimate Guide Conditional Wait
Use
This Conditional Waits in Scenario Editor
Use conditional waits when a Scenario Editor test needs to wait for application state, such as an element becoming visible, enabled, populated, or ready for interaction. Prefer conditional waits over fixed pauses whenever the timing depends on the application or network.
When to use a conditional wait
A page or component loads asynchronously.A buttonfeature isdisabled until validation completes.Search results, modal dialogs, or messages appear after an action.A stored value or validation depends on content generated during the run.
Good practices
Waitonly for thesmallestTestDesignerstableusing the GraalVM engine (AIQ 4.0.10 onwards) and overrides TestDesigner JS versus Sahiwait can have 1 or 2 parameters, the first one is duration and the second one is a condition, it has this format
wait(time,condition)
The second parameter could use quotes ore not and both syntax's are valid in AIQ 4.0.10, but have a small semantic difference
Without quotes
wait(X,isVisible(XX))
This is wait if X ms isVisible is false, will not wait otherwise, this is the same as
if (!isVisible(XX)){ wait(X) }The explanation of the behavior is detailed below
With quotes
wait(X,"isVisible()")
This is wait up to X ms while isVisible is false, will stop waiting once isVIsible becomes true, it is the same as
while (!isVisible(XX) total_wait_time < X){ wait(few_ms) }Conditional wait is based on JS and the concept its that condition is evaluated, now, to understand condition, it is important to understand that
provescondition is a function in thepageJS concept (for detailed definition check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function )For example, if in JS, you want a fucntion to be executed multiple times, you do
setInterval(function, ms)
This are valid expression wich will print hi every second
setInterval(()=>{console.log("hi")},1000)setInterval("console.log('hi')",1000)setInterval(()=>{console.log("hi")},1000)setInterval(function(){console.log("hi")},1000)This is
ready.Useanstableexpressionlocatorswhich will not print hi every second, it will print it only onesetInterval(console.log("hi"),1000)This is because you are passing undefined (The result of console.log) to the set interval method.
Similarly, you can use
ten_minutes = 600000//ten minutes in ms
wait(ten_minutes,"isVisible(link('Here'))")wait(ten_minutes,()=>isVisible(link("Here")))wait(ten_minutes,function(){return isVisible(link("Here"))})wait(ten_minutes,()=>{return isVisible(link("Here"))})This will wait up to 10 minutes, or less if the isVisible returns true before that time. Now, it should not take longer, but could take a little longer if the final isVisible calls overlaps the 10 minutes.
Keep in mind evaluating the function could trigger an exception, but that will not stop the script, a exception thrown will be considered as the function returning false.
Now a call like
wait(ten_minutes,isVisible(link("Here")))It will evaluate the is visible and
avoidwillwaitspasstiedthe value to the wait it is the same asvar result =isVisible(link("Here")) wait(ten_minutes,result)Therefore it can only
tohavevisual3position.behaviors-
Will return inmediatelly if the result was true.
Will wait failures10 asminutes application,if environment,the locator,result was false
Wil throw an error if the link or dataisVisible issuesmethod beforethrows increasingan timeoutexception.
Last updated: SeptemberJune 18,02, 20262023
If you have any feedback on this topic, please contact us at documentation@appvance.ai