Ultimate Guide Conditional Wait
This feature is only for the TestDesigner using the GraalVM engine (AIQ 4.0.10 onwards) and overrides href="/books/installation-and-configuration/page/testdesigner-js-versus-sahi"TestDesigner JS versus Sahi
wait 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 condition is a function in the JS 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 an expression which will not print hi every second, it will print it only one
setInterval(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 will pass the value to the wait it is the same as
var result =isVisible(link("Here"))
wait(ten_minutes,result)
Therefore it can only have 3 behaviors
-
Will return inmediatelly if the result was true.
-
Will wait 10 minutes if the result was false
-
Wil throw an error if the link or isVisible method throws an exception.
Last updated: June 02, 2023
If you have any feedback on this topic, please contact us at documentation@appvance.ai