Skip to main content

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

NameTypeDefaultDescription
conditionFunctionN/AThe condition to wait for.
timeoutNumber5000Timeout in milliseconds.
timeoutMsgStringN/AError message to throw when the timeout is reached.
intervalNumber500Interval 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",
},
);
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.