Skip to content

[Bug] .not.toBePresent and .not.toBeDisplayed fails #2013

@cchangenot

Description

@cchangenot

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.23.2

Node.js Version

v24.13.0

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

Upgrading expect-webdriverio from from 5.6.1 to 5.6.4 makes .not.toBePresent() and .not.toBeDisplayed() fail in some cases:

What is your expected behavior?

No response

How to reproduce the bug.

describe("toBePresent", () => {
  it("should open and close modal", async () => {
    await browser.url("https://ng-bootstrap.github.io/#/components/modal/examples");

    await $("button=Launch demo modal").click();

    const modal = $("ngb-modal-window");
    await expect(modal).toBeDisplayed();
    await browser.keys(Key.Escape);
    await expect(modal).not.toBePresent(); // This fails
  });
});

Workaround: using waitFor functions is working fine :

describe("toBePresent", () => {
  it("should open and close modal", async () => {
    await browser.url("https://ng-bootstrap.github.io/#/components/modal/examples");

    await $("button=Launch demo modal").click();

    const modal = $("ngb-modal-window");
    await expect(modal).toBeDisplayed();
    await browser.keys(Key.Escape);
    await modal.waitForDisplayed({reverse: true}); // This works
  });
});

Relevant log output

1) toBePresent should open and close modal
Expect $(`ngb-modal-window`) not to be present

Expected [not]: "not present"
Received      : "present"

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions