waitUntil
This wait command is your universal weapon if you want to wait on something. It expects a condition and waits until that condition is fulfilled with a truthy value. If you use the WDIO testrunner the commands within the condition are getting executed synchronously like in your test.
A common example is to wait until a certain element contains a certain text (see example).
Usage
browser.waitUntil(condition, { timeout, timeoutMsg, interval })
Parameters
Name | Type | Details |
---|---|---|
condition | condition to wait on | |
options optional | WaitUntilOptions | command options |
options.timeout optional | Number | timeout in ms (default: 5000) |
options.timeoutMsg optional | String | error message to throw when waitUntil times out |
options.interval optional | Number | interval between condition checks (default: 500) |
Examples
- Asynchronous Mode
- Synchronous Mode
example.html
<div id="someText">I am some text</div>
<script>
setTimeout(() => {
await $('#someText').html('I am now different');
}, 1000);
</script>
waitUntil.js
it('should wait until text has changed', async () => {
await browser.waitUntil(
async () => (await $('#someText').getText()) === 'I am now different',
{
timeout: 5000,
timeoutMsg: 'expected text to be different after 5s'
}
);
});
example.html
<div id="someText">I am some text</div>
<script>
setTimeout(() => {
$('#someText').html('I am now different');
}, 1000);
</script>
waitUntil.js
it('should wait until text has changed', () => {
browser.waitUntil(
() => ($('#someText').getText()) === 'I am now different',
{
timeout: 5000,
timeoutMsg: 'expected text to be different after 5s'
}
);
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.