cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Clicks do not always trigger event #25764

Closed liuliu-dev closed 1 year ago

liuliu-dev commented 1 year ago

Current behavior

when running cy.get('[data-cy=mobile-navbar-menu-button]').click();, sometimes the button won't be triggered, the button is visible, and adding should('be.visible') did not help with the situation.

Screen Shot 2023-02-09 at 3 48 38 PM

I tried adding wait() before clicks (suggestions from this issue: https://github.com/cypress-io/cypress/issues/25644), it fails much less frequently, but adding arbitrary waiting time is not a reliable option.

The test fails more often on ViewportPreset like "ipad-2" and "iphone-x", we didn't have this issue with v11

Desired behavior

No response

Test code to reproduce

describe(
  "test blog page on mobile",
  { viewportWidth: 768, viewportHeight: 1024 },
  () => {
    beforeEach(() => {
      // create the stub here
      const ga = cy.stub().as("ga");

      // prevent google analytics from loading and replace it with a stub before every
      // single page load including all new page navigations
      cy.on("window:before:load", win => {
        if (!Object.getOwnPropertyDescriptor(win, "ga")) {
          Object.defineProperty(win, "ga", {
            configurable: false,
            get: () => ga, // always return the stub
            set: () => {}, // don't allow actual google analytics to overwrite this property
          });
        }
      });

      cy.visit(
        "https://www.dolthub.com/blog/2020-03-06-so-you-want-git-for-data/",
      );
    });

    it(
      "should trigger nav button",
      { viewportWidth: 768, viewportHeight: 1024 },
      () => {
        cy.get(`[data-cy=mobile-navbar-menu-button]`).click();
        cy.get("[data-cy=mobile-navbar-links] > li").should("be.visible");
      },
    );
  },
);

Cypress Version

12.2

Node version

v18.14.0

Operating System

macOS 12.0.1

Debug Logs

No response

Other

No response

mschile commented 1 year ago

...we didn't have this issue with v11

@liuliu-dev, running the provided test locally on both Cypress v10 and v11 shows the same error. Are you seeing otherwise?

Image

liuliu-dev commented 1 year ago

...we didn't have this issue with v11

@liuliu-dev, running the provided test locally on both Cypress v10 and v11 shows the same error. Are you seeing otherwise?

Image

seems due to changes on our side, thanks for looking into it!