waitUntil
Overview
Use the waitUntil
command to wait for a specific condition to be met on the page in the browser.
Usage
await browser.waitUntil(condition, { timeout, timeoutMsg, interval });
Command Parameters
Name | Type | Default | Description |
condition | Function | N/A | The condition to wait for. |
timeout | Number | 5000 | Timeout in milliseconds. |
timeoutMsg | String | N/A | Error message to throw when the timeout is reached. |
interval | Number | 500 | Interval in milliseconds between condition checks. |
Usage Examples
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", async ({ browser }) => {
await browser.waitUntil(
async () => (await browser.$("#someText").getText()) === "I am now different",
{
timeout: 5000,
timeoutMsg: "expected text to be different after 5s",
},
);
});
Related Commands
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.