Cypress test always fails in GitHub Actions & headless, but not locally in normal mode?

See original GitHub issue

I have a Cypress test that checks for the presence of a data-cy within another data-cy.

This test passes when I run Cypress locally in Chrome. It fails when I run it in headless mode locally. It fails regardless of what mode it is run under, when ran in GitHub Actions.

When it fails locally in headless mode, I can see the element rendered that it is apparently failing to find on the DOM, in the screenshots & video.

I’m baffled. I’ve tried changing Node versions on GitHub Actions, I’ve tried a separate Cypress test step rather than using the Vue CLI. I’ve even tried running it within a Windows container and forcing Chrome instead of Electron. I’ve even tried adding sleeps/timeouts.

Here is the test:

  it("When I choose 4-4-2, I see the expected combination of players", () => {
    cy.get("[data-cy=formation-selector-1]").select("4-4-2");
    cy.get("[data-cy=formation-1]").within(() => {
      cy.get("[data-cy=goalkeeper]")
        .its("length")
        .should("eq", 1);
    });
  });

The error message always says: CypressError: Timed out retrying: Expected to find element: '[data-cy=goalkeeper]', but never found it.

Just to provide some context, the reason why I am using the within() function is because on the page, I have several different formation divs. Hence the appended -1 to the data-cy=formation-1. Every one of these has a div with data-cy=goalkeeper inside it. So the reason why I am using within() is to avoid having to append a similar unique identifier to the data-cy of each child element.

Does anyone have any idea, what the culprit possibly could be? Or something I can do to get to the bottom of it? Thanks.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Lusitaniaecommented, Oct 12, 2020

Issues running Headless come up a lot (search for Headless in the Issues),

see my comment for work around (running headful mode in CICD):

https://github.com/cypress-io/cypress/issues/8606#issuecomment-703544094

1reaction
nielsboeckercommented, Jan 22, 2021

After experiencing similar issues and spending the morning digging into the issue, I can confirm @Lusitaniae’s solution works for me as well.

I experienced that after migrating Cypress from 5.3.0 to 6.3.0, tests would pass locally but fail on CI (GitHub Actions). I’ve made sure both environments run Chrome 88. The problem was resolved by going headed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress test always fails in GitHub Actions ... - Stack Overflow
This test passes when I run Cypress locally in Chrome. It fails when I run it in headless mode locally. It fails regardless...
Read more >
Introduction | Cypress Documentation
What you'll learn An overview of Continuous Integration How to run Cypress tests in Continuous Integration How to configure Cypress in various CI....
Read more >
cypress-io/cypress - Gitter
The video record show that the page is blank and then fails when asserting ... that all my tests are run one after...
Read more >
Write E2E Tests Using Cypress And Run Them On ... - YouTube
Can you clone someone's web application, write end-to-end tests, and then ... Cypress test runner https://www. cypress.io/ - GitHub Actions ...
Read more >
Run your Cypress Tests in a Github Workflow
Introduction In my previous Cypress posts I've walked through how to get Cypress setup and... Tagged with github, cypress, javascript, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found