Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No session is defined with the name #22381

Closed
gajus opened this issue Jun 17, 2022 · 7 comments · Fixed by #23347
Closed

No session is defined with the name #22381

gajus opened this issue Jun 17, 2022 · 7 comments · Fixed by #23347
Assignees
Labels
topic: session Issues when using session command type: bug

Comments

@gajus
Copy link

gajus commented Jun 17, 2022

Current behavior

Keep running into behavior where a recently declared session is no longer available.

It works on the first test, but fails on the second. Appears to be an issue with how we utilize clearAllSavedSessions to reset all sessions.

Desired behavior

Declared sessions persist.

Test code to reproduce

beforeEach(() => {
  cy.wrap(Cypress.session.clearAllSavedSessions());
});

it('a', () => {
  cy.session('INDY', () => {});
  cy.session('CLIENT', () => {});

  cy.session('INDY');
});

it('b', () => {
  cy.session('INDY', () => {});
  cy.session('CLIENT', () => {});

  cy.session('INDY');
});

Cypress Version

10.1.0

Other

Screen Shot 2022-06-17 at 10 28 45 AM

@gajus
Copy link
Author

gajus commented Jun 17, 2022

Actually, whether clearAllSavedSessions is used or not does not make a difference.

@gajus
Copy link
Author

gajus commented Jun 17, 2022

Works:

it('a', () => {
  cy.session('INDY', () => {
    'a';
  });
  cy.session('INDY');
});

it('b', () => {
  cy.session('INDY', () => {
    'b';
  });
  cy.session('INDY');
});

Does not work:

it('a', () => {
  cy.session('INDY', () => {
    'a';
  });
  cy.session('INDY');
});

it('b', () => {
  cy.session('INDY', () => {
    'a';
  });
  cy.session('INDY');
});

@gajus
Copy link
Author

gajus commented Jun 17, 2022

@gajus
Copy link
Author

gajus commented Jun 17, 2022

I found that:

beforeEach(() => {
  // @ts-expect-error Accessing internal property to bypass a bug described in https://github.com/cypress-io/cypress/issues/22381
  cy.wrap(Cypress.state('activeSessions', {}));
  cy.wrap(Cypress.session.clearAllSavedSessions());
});

gives the desired behavior.

@emilyrohrbough emilyrohrbough self-assigned this Jun 22, 2022
@emilyrohrbough emilyrohrbough added the topic: session Issues when using session command label Jun 22, 2022
@emilyrohrbough
Copy link
Member

@gajus Thank you for logging this issues. I can confirm this is a bug.

It appears it is related to how we are tracking session ids registered to a particular test. It seems we are only adding unique session ids for a suite instead of adding the session ids associated with the test itself.

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/sessions/index.ts#L116

Glad to hear you have a working around for the time being.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 16, 2022

The code for this is done in cypress-io/cypress#23347, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Aug 16, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 16, 2022

Released in 10.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: session Issues when using session command type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants