Avoiding browser.pause with WebDriver IO (JavaScript)

Avoiding browser.pause with WebDriver IO (JavaScript)

In automated testing with WebDriver IO, using browser.pause is discouraged because it increases test flakiness and may lead to inaccurate results. Instead, proper handling of synchronization is crucial for ensuring a stable and reliable test. This article presents a method to avoid browser.pause using WebDriverWait, a more reliable approach for dealing with synchronization issues.

Using WebDriverWait for Synchronization

The WebDriverWait class provides a more efficient way to handle synchronization by allowing you to wait for specific conditions to be met before proceeding with the test. This helps to ensure that elements are ready for interaction and reduces the likelihood of flaky tests.

const element = await browser.$('#firstHeading');

await browser.waitUntil(async () => {
    return await element.isDisplayed();
}, { timeout: 5000 });

Here is an example test that uses the above code snippet.

See Working Example


Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.