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

152
Visualizações
How to retrieve Token for API calls in cypress

Due to a lack of knowledge in JS, I do face with below problem. I do automation testing with cypress and for external API endpoints, I need to use Dynamic Token that expires every 3600 secs. I did some short research and find out that, for reaching to JWT Token I will need 1st SSO login (that my app has). Then use the below script. But I don't know what to do after this.

 it('the value of JWT Token should exist in localStorage', () => {
        cy.getLocalStorage('JWT_DATA').then(lsData => {
            cy.log('the token', lsData); // I get JWT Token in here
        });
    });

The result of this script is only printing the TOKEN. But I need to store it somehow and then be able to reuse it for every different API endpoint call.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use Cypress.env for this. Then you can use the token throughout the test anywhere.

it('the value of JWT Token should exist in localStorage', () => {
  cy.getLocalStorage('JWT_DATA').then((lsData) => {
    cy.log('the token', lsData) // I get JWT Token in here
    Cypress.env('token', lsData)
  })
})

To use it, you can do

Cypress.env('token')
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