cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.

Home Page:https://cypress.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cy.session timeouts in e2e tests with Cypress 12.3

mikstime opened this issue · comments

Current behavior

After migration from Cypress 10.10.0 to 12.3.0 cy.session command started to timeout occasionally around this line.

Desired behavior

cy.session does not timeout

Test code to reproduce

Not ready yet. We were unable to reproduce error when launching only the problematic specs but it occurs when running many specs at once.

Example spec file looks alike

// let login = 'testuser';
// let password = 'password';
// let domains = ['https://domain.com', 'https://domain.net', 'https://domain.us', 'https://domain.uk'];
for(const domain of domains) {
    it('name', { baseUrl: domain }, () => {
        cy.session([login, domain], () => {
            cy.request({
                method: 'POST',
                url: `${domain}/login`,
                headers: {
                    'X-Requested-With': 'XMLHttpRequest',
                    Accept: 'application/json, text/javascript, */*; q=0.01',
                },
                body: `login=${login}&password=${password}`,
            });
        }, {
            validate() {
                const cookie = cookies.filter(c => c.name === 'login')[0];
                cy.wrap(cookie).its('value').should('eq', login);
            },
        });
        cy.visit(domain);
        // ...
    });
}

Cypress Version

12.3.0

Node version

16.18.0

Operating System

linux-ubuntu-16-04-xenial

Debug Logs

CypressError: `cy.then()` timed out after waiting `4000ms`.

Your callback function returned a promise that never resolved.

The callback function was:

async () => {
          setSessionLogStatus(_utils__WEBPACK_IMPORTED_MODULE_6__[/* statusMap */ "g"].inProgress(step));
          await Object(_utils__WEBPACK_IMPORTED_MODULE_6__[/* navigateAboutBlank */ "e"])();
          await sessions.clearCurrentSessionData();
          return cy.whenStable(() => createSession(existingSession, step));
        }

https://on.cypress.io/then
    at <unknown> (https://<domain>/__cypress/runner/cypress_runner.js:135630:83)
    at tryCatcher (https://<domain>/__cypress/runner/cypress_runner.js:8914:23)
    at <unknown> (https://<domain>/__cypress/runner/cypress_runner.js:4036:41)
    at tryCatcher (https://<domain>/__cypress/runner/cypress_runner.js:8914:23)
    at Promise._settlePromiseFromHandler (https://<domain>/__cypress/runner/cypress_runner.js:6849:31)
    at Promise._settlePromise (https://<domain>/__cypress/runner/cypress_runner.js:6906:18)
    at Promise._settlePromise0 (https://<domain>/__cypress/runner/cypress_runner.js:6951:10)
    at Promise._settlePromises (https://<domain>/__cypress/runner/cypress_runner.js:7027:18)
    at _drainQueueStep (https://<domain>/__cypress/runner/cypress_runner.js:3621:12)
    at _drainQueue (https://<domain>/__cypress/runner/cypress_runner.js:3614:9)
    at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (https://<domain>/__cypress/runner/cypress_runner.js:3630:5)
    at Async.drainQueues (https://<domain>/__cypress/runner/cypress_runner.js:3500:14)

Other

This happens both when session step === 'create' or step === 'recreate'.

We use:

  • testIsolation: false.
  • Electron (desktop) 106 (headless)
  • Chromium (desktop) 90 (headless)

There was an attempt to run these tests without using cy.session which resulted in a different error. Tests passed successfully after relaunch

OUT       cy:request ✔  POST https://auth.domain.com/login
OUT                     Status: 200
OUT                     Response body: <body>...
...
OUT       cy:command ✔  getAllCookies	
OUT       cy:command ✔  wrap	Object{7}
OUT       cy:command ✔  its	.value
OUT       cy:command ✔  assert	expected **username** to equal ** username**
OUT       cy:command ✘  origin	https://auth.domain.com
OUT       cy:command ✘  visit	https://anothersubdomain.anotherdomain.com
OUT       cy:command ✘  uncaught exception	Error: backend:request failed to receive a response from the primary Cypress spec bridge within 4 second.

Hi @mikstime. Thank you for opening an issue. I see you are working on a reproduction so I will make the issue for a "needs repro". Just to confirm, this issue happens in chromium 90, Electron 106 with test isolation off? Have you tried mix/matching some of those config options to see if a different result yields?

Just to confirm, this issue happens in chromium 90, Electron 106 with test isolation off?

Yes.

Have you tried mix/matching some of those config options to see if a different result yields?

I've done some testing with testIsolation enabled and have not been able to reproduce these errors. Have not tried other browsers though.

Do you have any examples to reproduce error below or any ideas why it occurs?
backend:request failed to receive a response from the primary Cypress spec bridge within 4 second.

Do you have any examples to reproduce error below or any ideas why it occurs? backend:request failed to receive a response from the primary Cypress spec bridge within 4 second.

That usually happens if something failed when setting up the communication channels for the spec bridge when using cy.origin. Are you using cy.origin anywhere?

Are you able to try maybe firefox and see if the result may be different? Interested to see if this might be browser specific.

Once your reproduction is available we can start digging into this.

That usually happens if something failed when setting up the communication channels for the spec bridge when using cy.origin. Are you using cy.origin anywhere?

There is a case when authentication url is on domain x and we open domain y afterwards. Which is exactly the case producing described error.

Are you able to try maybe firefox and see if the result may be different?

Sorry, don't have access to firefox in CI currently

Not ready yet. We were unable to reproduce error when launching only the problematic specs but it occurs when running many specs at once.

@mikstime, have you been able to create the reproduction? Right now there doesn't seem to be enough information to reproduce the problem on our end. Unless we receive a reliable reproduction, we'll eventually have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

We decided to use testIsolation as a solution for now.

describe('specs', { testIsolation: true}, () => {
    it('test', () => {
        //
    });
});

Hello, I am getting this error in the latest Cypress version 12.17.2. I am using a cucumber-preprocessor and no option to set testIsolation. May I ask for any alternative solution?

Hi, i'm getting the same error over a test that worked perfectly for at least 1/2 months, until now:
image

This happened on Electron env, v106, and Cypress v12.13.0. I updated Cypress to last version now, run it again and the problem was fixed, but it's a random event, it does not always happen, so I cannot guarantee the problem is really solved. In case it is, please close this issue and apologies for reopening it! Thanks!

Stack trace:
at Context.eval (webpack:///./cypress/e2e/finales.cy.js:51:11)
From previous event:
at Context.origin (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:147797:14)
at wrapped (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:160605:43)
at (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:159439:15)
From previous event:
at CommandQueue.runCommand (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:159405:8)
at next (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:159605:19)
at (https://alumnos.unsta.edu.ar/__cypress/runner/cypress_runner.js:159626:16)

Edit: Effectively, the error is still there.