Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress - Timed out retrying after 4000ms: Expected to find element - only in Jenkins

I have a grouping of Cypress tests that are failing, only in my Jenkins environment. An entire describe block is failing to find an element. Every test in the block starts with the same commands:

describe("This section of tests", () => {
  it("Test for something in this section", () => {
    cy.login(); // custom login command, works in all other test blocks
    setupPage(); // page setup function, no problems in all other test blocks
    cy.wait(10000); // desperation wait

    cy.get("#toggle-detail-pane-button").click(); // issue here!
    // all tests in block run more assertions and commands after this
  });

  // more similar tests in block
});

// more describe blocks that also use cy.login and setupPage, with no issue

When I run these tests in the cypress test UI, they all pass. When I run them in the terminal on my machine with npx cypress run, they pass. When I ssh into a remote OpenStack terminal which is set up to run my project and run cypress, and run npx cypress run, they pass.

When I run the tests in Jenkins, which uses a handful of identical OpenStack instances to run cypress in parallel, the tests fail, consistently, with the following message:

AssertionError: Timed out retrying after 4000ms: Expected to find element: `#toggle-detail-pane-button`, but never found it.

      at Context.eval (http://localhost:3000/__cypress/tests?p=cypress/integration/stuff/mytests.spec.js:519:8)

I have tried reorganizing my tests, rewriting them, etc, but no luck. I cannot figure out what is going wrong here. My Jenkins environment uses a custom sorry-cypress setup, and for some reason, the dashboard is not registering the tests, so I can't go and view any screenshots or videos (that is a whole separate can-of-worms problem).

Why would only these tests fail only in my CI/CD env? How can I even begin to debug this?

Edit: screenshots

I was able to rerun the CI/CD with screenshots and videos, and then I was able to scp the files off of the instance with the failing tests. When running on my machine, cypress has no problem finding the element:

enter image description here

When using the cypress selector playground on my machine, it finds it as well:

enter image description here

But in the screenshot I pulled off of the openstack instance running exactly the same test, it can't find it:

enter image description here

(Sorry for all the green, this is a proprietary app)

What gives?

like image 568
Seth Lutske Avatar asked Sep 07 '25 10:09

Seth Lutske


1 Answers

Please update the default command timeout in cypress.config.js file using below line:

defaultCommandTimeout: 10000

Instead of 10000 you can use any value of time in miliseconds. Using this your, timeout issue will be resolved.

like image 197
user3548006 Avatar answered Sep 10 '25 10:09

user3548006