0

I think I've found an issue with cy.session(), but before opening one in the GitHub wanted to hear your ideas on my problem itself:

Implemented cy.session(), and it worked! For most of the pages...

The issue is with pages with <select> elements. After session() was implemented, the cy.select() stopped working. It chose the right option, and then it went right back to the previously selected option. The strangest thing is that is not seen even in the DOM snapshots. Removing cy.session() made everything work again.

So, my question is:

Does it feel like a cypress bug? Has anyone encountered this issue and got it somehow resolved? Cannot imagine any way how cy.selecting elements is related to sessions.

EDIT:

After further investigation, I found that selecting a page option changes one specific cookie value. This cookie has the page type code, thus I think that the new value is not saved to the cookie as it was before without cy.session()

Manually selecting in the browser from cypress open doesn't work either! After discovering that, I am pretty sure that it is the cypress bug.

As it was requested, here is my code:

commands.ts

Cypress.Commands.add('login', (user: User) => {
    return cy.session(
        [user.api_key],
        () => {
            cy.request({
                ...
            });
        },
        {
            validate() {
                cy.visit('/');
                cy.contains(user.username, { matchCase: false });
            },
            cacheAcrossSpecs: true,
        }
    );
});

e2e.ts

beforeEach(() => {
    cy.getCurrentUser().then((user) => {
        cy.login(user);
    });
});
  • 1
    Are the selections updating a cookie, localStorage or SessionStorage? `cy.session()` will cache that data, so there's a decent chance that the previously selected value is cached, and that is causing the issue. – agoff Oct 03 '22 at 13:46
  • 1
    Negative, `cy.session()` only cached the values set by it's own callback. – Ferando Oct 03 '22 at 20:32
  • What is the code please - sounds like correlation not causation. – Ferando Oct 03 '22 at 20:34
  • @agoff yes, selections are updating a cookie. This cookie is set after the first visit to the specific page, not during log in, so if Ferando is correct, it should not be cached in the session. Is it possible that the session somehow blocks changing the cookie value? – Eva-Anna Klugman Oct 04 '22 at 08:20
  • @Ferando sorry, just noticed that I didn't ping you earlier. Added code as requested. – Eva-Anna Klugman Oct 04 '22 at 18:42

1 Answers1

0

This issue gets resolved in Cypress 10.10!

Opened issue in cypress' GitHub and got an answer:

https://github.com/cypress-io/cypress/issues/24149