cypress-io / cypress

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

Test Timing out on Github Actions - Cypress 7.0 #15990

Closed Josehower closed 3 years ago

Josehower commented 3 years ago

Current behavior

On Cypress 7.0 Test is failing on GitHub Actions due Timeout, Locally the test is working good This test never failed before on older cypress versions

Local Test

image

Github Actions

image

Desired behavior

This test should be working as good as always

Test code to reproduce

Test Code

describe('Navigation', () => {
  it('checks that the app reads the cookie as expected and shows the right courses based on its authorization', () => {
    cy.visit('/');
    cy.get('[data-cy=prep-course]').should('not.exist');
    cy.get('[data-cy=btcmp-course]').should('not.exist');
    cy.setCookie('courses', cookiePrepPreview);
    cy.visit('/');
    cy.get('[data-cy=prep-course]').should('be.visible');
    cy.get('[data-cy=btcmp-course]').should('not.exist');
    cy.get('preview-lock').should('be.visible');
    cy.setCookie('courses', cookiePrep);
    cy.visit('/');
    cy.get('[data-cy=prep-course]').should('be.visible');
    cy.get('[data-cy=btcmp-course]').should('not.exist');
    cy.setCookie('courses', cookieBoth);
    cy.visit('/');
    cy.get('[data-cy=btcmp-course]').should('be.visible');
    cy.get('[data-cy=prep-course]').should('be.visible');
  });

  it('checks that the links for the courses work as expected and the courses pages show the right content', () => {
    cy.setCookie('courses', cookieBoth);
    cy.visit('/');
    cy.get('[data-cy=prep-course]').should('be.visible').click();
    cy.get('[data-cy=bootcamp-prep]').should('be.visible');
    cy.url().should('include', 'prep-l-webfs-gen-0');
    cy.contains('001 - HTML: Definition');
    cy.contains('002 - HTML: Elements, Tags & Attributes');
    cy.contains('003 - HTML: Interactive Elements');
    cy.contains('004 - CSS: Definition');
    cy.contains('005 - CSS: Selectors & Declarations');
    cy.contains('006 - CSS: Selectors in Detail');
    cy.contains('007 - CSS: Layout');
    cy.contains('008 - JS: Definition');
    cy.contains('009 - JS: Variables');
    cy.contains('010 - JS: Functions');
    cy.visit('/');
    cy.get('[data-cy=btcmp-course]').should('be.visible').click();
    cy.url().should('include', 'btcmp-l-webfs-gen-0');
    cy.contains('001 - Tasks');
    cy.contains('002 - Documentation');
    cy.contains('Cheatsheet');
  });
});

Versions

Last working version

`"cypress": "6.8.0"`

Unexpected behavior version

`"cypress": "7.0.1"`

additional comments

I can confirm that the test duration is significantly longer than the previous version

image

fourcolors commented 3 years ago

I have a very similar issue right now that's been affecting several tests at our company. Locally it's working, even using the electron browser but on circle ci it fails.

image

  cy.get('[aria-expanded=true]').should('exist');

We are running "cypress": "^6.8.0",

All I can think of is that on CI it's headless. I'm not sure why this would make selectors randomly fail though.

We found this 👇🏻 helps and seperating out the test but I believe this should be working

cy.get('[data-cy=selector]').then(($el) => {
  Cypress.dom.isVisible($el) // true
})
bahmutov commented 3 years ago

I think the longer timing due to performance regression is affecting the tests. For now I suggest sticking with the last known Cypress version or trying increasing the default command timeout setting in the cypress.json file.

Hypercubed commented 3 years ago

I was attempting to reproduce (https://github.com/Hypercubed/cypress-issue) an issue we were seeing in our app that looks related this ticket. I am hesitant to post this as a bug since I think, for the most part, it's a flaky test on our end. However, it does show that there is some sort of performance regression in v7.x vs v6. Increasing command timeout doesn't help in our case since it boils down to how long takes takes cypress to run the next command when other things are going on in the app. There has been nothing I can find that can force Cypress to execute the commands fast enough to capture the DOM. Hope this info helps.

jennifer-shehane commented 3 years ago

Can you all try updating to Cypress 8.0 and report if this issue is still happening? We've addressed some performance issues that were introduced with the screen size changes.

OlgaShchekina commented 3 years ago

It seems like it's working now. We will test for a couple more days.

But the cy.stub() does not work and neither do the recipes from here: https://glebbahmutov.com/blog/stub-window-open/ It worked well with the older version.

Screen Shot 2021-07-20 at 4 52 10 PM
jennifer-shehane commented 3 years ago

Closing as I believe this is resolved in 8.0.

In 7.0 the screen size was increased when running headlessly. This will slow down runtime and in some cases with low resourced machines (as GitHub Actions may be depending on the background process) it can cause hanging. In 8.0 we reverted this change back to pre-7.0 screen size.