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

375
Visualizações
How to clear local storage in Cypress test?

At the beginning of my Cypress test scenario, I need to click the Agree and Proceed button on the below IFrame:

enter image description here

The problem is that after clicking this button during my first test run, the user's consent is stored in the local storage as you can see here:

storage

If I re-run my test again, it will fail because the local storage is storing the user's consent, so the IFrame asking for consent won't appear.

If I manually clear the truste.consent.willistowerswatson.com key from local storage and re-run my test, it will pass.

I need to somehow automatically clear this value.

I tried to specify the key value with the below code, but it isn't clearing the value:

beforeEach(() => {
    cy.clearLocalStorage('truste.consent.willistowerswatson.com')
})

it('First test', () => {
    cy.visit('http://www.willistowerswatson.com/ICT');
    cy.iframe('[id^=pop-frame]').find('.call').should('have.text', 'Agree and Proceed').click()
})

Can someone explain how I can clear this value from local storage, so my test can re-run without any issue?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can remove this specific key by running:

localStorage.removeItem(‘truste.consent.willistowerswatson.com‘);

Alternatively, if desired, you can delete the entire localStorage as follows:

localStorage.clear();

You also find more info in the MDN Web Docs here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

over 4 years ago · Santiago Trujillo 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