Skip to content

Nightwatch: an awaited waitForElementPresent returns before the wait runs when the plugin is loaded #457

Closed

Description

@vishnuv688

What happens

With @wdio/nightwatch-devtools loaded, an awaited waitForElementPresent returns before the wait has run, so the commands after it run first:

await browser.click('button[type="submit"]')        // navigates to /secure
await browser.waitForElementPresent('#flash', 2000)  // returns at once
const text = await browser.getText('#flash')         // runs before the wait
await browser.click('#logout')                       // navigates back to /login
// only now does the wait poll for #flash, on /login, and time out

The test then fails on a timeout it would not have hit. The same spec against the same pages with the plugin removed passes, with the element present after about 500 ms. Seen in 9 of 9 runs while extending the conformance scenarios (#455).

Why it matters

The plugin changes the outcome of the user's own test, which is the one thing an observer must never do.

Expected

await browser.waitForElementPresent(...) resolves only after the wait has finished, with or without the plugin, so the following commands run against the page the wait saw.

Where to look

The plugin wraps Nightwatch commands to capture them (packages/nightwatch-devtools/src/helpers/browserProxy.ts). The wrapper likely resolves the awaited chainable before Nightwatch's queued wait has executed, so the user's await no longer waits for it.

Activity

  1. vishnuv688 commented on Oct 27, 2026

    @vishnuv688
    MemberAuthor

    Fixed by #467. The cause was the plugin's performance read: half a second after a navigation it ran browser.execute, a queued Nightwatch command fired from a timer, which became a child of whatever command the test was running and resolved that command's await early. An awaited waitForElementPresent that the read landed inside therefore returned before the wait ran. #467 moved the read onto the raw WebDriver transport. With it on main, the conformance suite's wait-order gap (the wait landing after its test's assertion in 15 of 15 runs) and the login-test-fails gap both went stale, and three runs in all BiDi modes passed without them; the gaps are removed in #465.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions