Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
Sessions/Cookies in Cypress

I am testing a website that you have to add card details to, in order to do this you need to redirect to a payment providers site to add the details. When you have completed the form and try and return to the main site you get a error saying "session expired or cookies not enabled". I have used the preserve once method to save the session ID but it doesn't seem to be working. I can save auth cookies on the main site, but when I move to the credit card provider url the cookies don't save. Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe try this:

In commands.json:

Cypress.Commands.add('storeSessionData',()=>{
let str = [];
cy.getCookies().then((cookie) => {
    cy.log(cookie);
    for (let l = 0; l < cookie.length; l++) {
        if (cookie.length > 0 && l == 0) {
            str[l] = cookie[l].name;
            Cypress.Cookies.preserveOnce(str[l]);
        } else if (cookie.length > 1 && l > 1) {
            str[l] = cookie[l].name;
            Cypress.Cookies.preserveOnce(str[l]);
        }
    }
});
})

Then in your test code within the describe block:

afterEach(() => {
    cy.storeSessionData();
});

This should store your session data, so you can maintain a session at the end of each test. Note, at the end of each 'it' block, the default behaviour is to clear cookies, so this mitigates that

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda