15

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?

Seth Lutske
  • 9,154
  • 5
  • 29
  • 78
  • Not that it helps you but I like your `// desparation wait` comment. I used such in the past as well. And I like both Jenkins and Cypress. Can you reproduce it with an MCVE and post it in a JS/HTML snippet here? Can you disable the parallel test runs on Jenkins temporarily or did you try that too already? – Gerold Broser Aug 13 '21 at 21:22
  • Ouch! https://docs.sorry-cypress.dev/ci/jenkins → ⚠ Under construction – Gerold Broser Aug 13 '21 at 21:48
  • Yeah there's no documentation there, so I basically [wrote my own](https://medium.com/geekculture/parallelizing-cypress-with-jenkins-aws-and-sorry-cypress-8241331fe50f). As far as a MCVE, I'm really not sure how to do that considering it involves a complex and proprietary react codebase, with cypress, jenkins, and cloud computer resources. I can try running the testing over jenkins not in parallel, but ultimately I need a solution that works in parallel. I'll try that as soon as I can and report back. – Seth Lutske Aug 13 '21 at 22:12
  • I think I may also invest the time in getting sorry-cypress to work properly so that images and videos are properly uploaded to the sorry-cypress dashboard. If I can manage that, I may be able to see what the heck is going on in those tests that's causing failures. – Seth Lutske Aug 13 '21 at 22:13
  • Hats off! Very good article! Are you aware of that you could simplify your stage steps, which are all the same there, with a single line calling a [Shared Library](https://www.jenkins.io/blog/2017/02/15/declarative-notifications/#moving-notifications-to-shared-library)? – Gerold Broser Aug 13 '21 at 23:26
  • Yeah I've heavily refined my actual code since having written that article, I guess I should update it, but yes, agreed, no need to write the same 4 lines of code 4 times over – Seth Lutske Aug 14 '21 at 00:06
  • BTW, since you seem to be a JS front-end guy. Perhaps you have an answer to [this one](https://stackoverflow.com/q/68704174/1744774). I usually work more on Java back-end and DevOps. – Gerold Broser Aug 16 '21 at 14:22

4 Answers4

6

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.

Nikola Lukic
  • 4,001
  • 6
  • 44
  • 75
user3548006
  • 79
  • 1
  • 1
  • below is my overall code in cypress.config.js: const { defineConfig } = require("cypress"); module.exports = defineConfig({ defaultCommandTimeout: 8000, pageLoadTimeout:10000, e2e: { setupNodeEvents(on, config) { // implement node event listeners here }, specPattern: 'cypress/integration/examples/*.js', } }); – user3548006 Sep 25 '22 at 17:57
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – jasie Sep 29 '22 at 10:27
2

That means there's an issue with your cy.visit() command. The page is not being loaded before the test that's why

  • 1
    The page is being loaded. The screenshots above clearly show that (though perhaps the green NDA coverup makes that unclear)...but that is definitely not the answer. Upgradinf to cypress ^8 seems to have solved the problem – Seth Lutske Oct 06 '21 at 13:59
0

i resolve Timed out retrying after 4000ms: Expected to find content: 'Name' within the element... cy.wait(6000);

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 26 '23 at 18:51
-3

I had a similar problem. I solved it by getting the element by a selector or class instead of its id.

I went from:

cy.get('#mat-options-text').click()

to

cy.get('mat-options').click()
Sarai
  • 1
  • 1