# Use Conditional Waits in Scenario Editor

This feature is only for the TestDesigner using the GraalVM engine (AIQ 4.0.10 onwards) and overrides [TestDesigner JS versus Sahi ](/books/installation-and-configuration/page/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

<div id="bkmrk-wait%28time%2Ccondition%29" style="border-width:1px;"><div>```
wait(time,condition)
```

 </div> </div>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

<div id="bkmrk-wait%28x%2Cisvisible%28xx%29" style="border-width:1px;"><div>```
wait(X,isVisible(XX)) 
```

 </div> </div>This is wait if X ms isVisible is false, will not wait otherwise, this is the same as

<div id="bkmrk-if-%28%21isvisible%28xx%29%29%7B" style="border-width:1px;"><div>```
if (!isVisible(XX)){
  wait(X)
}
```

 </div> </div>The explanation of the behavior is detailed below

##### With quotes

<div id="bkmrk-wait%28x%2C%22isvisible%28%29%22" style="border-width:1px;"><div>```
wait(X,"isVisible()") 
```

 </div> </div>This is wait up to X ms while isVisible is false, will stop waiting once isVIsible becomes true, it is the same as

<div id="bkmrk-while-%28%21isvisible%28xx" style="border-width:1px;"><div>```
while (!isVisible(XX) total_wait_time < X){
  wait(few_ms)
}
```

 </div> </div>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](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

<div id="bkmrk-setinterval%28function" style="border-width:1px;"><div>```
setInterval(function, ms)
```

 </div> </div>This are valid expression wich will print hi every second

<div id="bkmrk-setinterval%28%28%29%3D%3E%7Bcon" style="border-width:1px;"><div>```
setInterval(()=>{console.log("hi")},1000)
```

 </div> </div><div id="bkmrk-setinterval%28%22console" style="border-width:1px;"><div>```
setInterval("console.log('hi')",1000)
```

 </div> </div><div id="bkmrk-setinterval%28%28%29%3D%3E%7Bcon-1" style="border-width:1px;"><div>```
setInterval(()=>{console.log("hi")},1000)
```

 </div> </div><div id="bkmrk-setinterval%28function-1" style="border-width:1px;"><div>```
setInterval(function(){console.log("hi")},1000)
```

 </div> </div>This is an expression which will not print hi every second, it will print it only one

<div id="bkmrk-setinterval%28console." style="border-width:1px;"><div>```
setInterval(console.log("hi"),1000)
```

 </div> </div>This is because you are passing undefined (The result of console.log) to the set interval method.

Similarly, you can use

<div id="bkmrk-ten_minutes-%3D-600000" style="border-width:1px;"><div>```
ten_minutes = 600000//ten minutes in ms
```

 </div> </div><div id="bkmrk-wait%28ten_minutes%2C%22is" style="border-width:1px;"><div>```
wait(ten_minutes,"isVisible(link('Here'))")
```

 </div> </div><div id="bkmrk-wait%28ten_minutes%2C%28%29%3D" style="border-width:1px;"><div>```
wait(ten_minutes,()=>isVisible(link("Here")))
```

 </div> </div><div id="bkmrk-wait%28ten_minutes%2Cfun" style="border-width:1px;"><div>```
wait(ten_minutes,function(){return isVisible(link("Here"))})
```

 </div> </div><div id="bkmrk-wait%28ten_minutes%2C%28%29%3D-1" style="border-width:1px;"><div>```
wait(ten_minutes,()=>{return isVisible(link("Here"))})
```

 </div> </div>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

<div id="bkmrk-wait%28ten_minutes%2Cisv" style="border-width:1px;"><div>```
wait(ten_minutes,isVisible(link("Here")))
```

 </div> </div> It will evaluate the is visible and will pass the value to the wait it is the same as

<div id="bkmrk-var-result-%3Disvisibl" style="border-width:1px;"><div>```
var result =isVisible(link("Here"))
wait(ten_minutes,result)
```

 </div> </div>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.
 
<div id="bkmrk-last-updated%3A-june-0">---

Last updated: <span class="mc-variable General.NewDateTimeVariable variable">June 02, 2023</span>

If you have any feedback on this topic, please contact us at <documentation@appvance.ai>

</div>