waitUntil
Overview
Use the waitUntil
command to wait until a specific condition is met on the page in the browser.
Usage
await browser.$(selector).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(() => {
document.getElementById("someText").innerHTML = "I am now different";
}, 1000);
</script>
waitUntil.js
it("should wait until text has changed", async ({ browser }) => {
const elem = await browser.$("#someText");
await elem.waitUntil(
async function () {
return (await this.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.