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

151
Vistas
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 Respuestas
Responde la pregunta

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 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