Prepending Stale Cookies to requests after 10.3
See original GitHub issueCurrent behavior
We use cy.session+cy.origin (see code below) to login with Keycloak which is hosted on a different domain. This always worked well until updating from Cypress 10.2 to 10.3.
After the first tests, the session seems broken, although Cypress logs “Validate Session: valid”. Authentification is no longer established. When I add a cy.wait(1000)
between visit
and contains
in the test code of it('starts again'
I can see that the browser is at the login screen again. There is also this error:
Timed out after waiting 60000ms for your remote page to load on origin(s):
- http://localhost:4200
A cross-origin request for https://login… was detected.
Same happens even for the first test if I rerun all tests using the “Run All Tests” button.
Desired behavior
Cypress should be able to store and recover the session (cookies?), as it already did before 10.3.
Test code to reproduce
In support/commands.ts
:
Cypress.Commands.add('cachedLogin', () => {
const args = { user };
cy.session(
args,
() => {
cy.visit('/');
cy.origin(KEYCLOAK_DOMAIN, { args }, ({ user }) => {
cy.get('#username').type(user.username);
cy.get('#password').type(user.password);
cy.get('#kc-login').click();
});
cy.url().should('contain', Cypress.config('baseUrl'));
},
{
validate() {
cy.request('/').its('status').should('eq', 200);
},
}
);
});
In Cypress-issue-22751.cy.ts
:
describe('issue 22751 reproducer', () => {
beforeEach(() => {
cy.cachedLogin();
});
it('starts', () => {
cy.visit('/');
cy.contains('Start');
});
it('starts again', () => {
cy.visit('/');
// cy.wait(1000); // add line to see that browser is at login screen
cy.contains('Start'); // fails on Cypress 10.3; "Timed out after waiting 60000ms for your remote page to load on origin(s):"
});
});
Cypress Version
10.3, 10.3.1, 10.4
Other
Tested with Chrome, Edge, Electron.
Issue Analytics
- State:
- Created a year ago
- Comments:20 (10 by maintainers)
Top GitHub Comments
@AtofStryker Here is a repo with the reproducible error https://github.com/Sebkasanzew/cypress-issue-22751.
It was easier than I thought 😅. Thanks for the template @iomedico-beyer .
@sebkasanzew I was able to clone your reproduction and was able to reproduce the issue. I am pretty sure I know what the issue is, as we prepend updated cookies to the request and do not remove the stale values. This also explains why the cookie size is just about double on the request. We likely need to adapt this logic to override the previous cookie values, which should lead to expected behavior.