Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda