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
Param | Type | Details |
---|---|---|
condition optional | param | condition to wait on |
timeout optional | param | timeout in ms (default: 500) |
timeoutMsg optional | param | error message to throw when waitUntil times out |
interval optional | param | interval between condition checks (default: 500) |
Example
<div id="someText">I am some text</div>
<script>
setTimeout(function() {
$('#someText').html('I am now different');
}, 1000);
</script>
it('should wait until text has changed', function () {
browser.waitUntil(function () {
return browser.getText('#someText') === 'I am now different'
}, 5000, 'expected text to be different after 5s');
});