Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Guardar datos de DB y luego usarlos en el cuerpo para API en cypress

Estoy tratando de guardar un token de DB y pasar el token en la siguiente solicitud de API en el cuerpo. He escrito el siguiente código pero no funciona, por favor ayuda.

 it.only('Change Password', () => { cy.ResetPassAPI(globalThis.data.dradminemail);// this generates a token in DB const resetoken = cy.task( 'queryDb', `select _Token from tokens WHERE _Member_Id = 25372 and _Token_Type = "resetPassword" ORDER BY _id DESC LIMIT 1`,); // saving the token from DB generate from above cy.request({ method: 'PATCH', url: 'https://xxx/xx/xx/changePasswordWithToken', body: { confirmPassword: 'xxx', password: 'xx', token: resetoken, //passing the saved token from database uid: 1234, }, }); });

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede usar Cypress.env() para esto.

 it.only('Change Password', () => { cy.ResetPassAPI(globalThis.data.dradminemail) // this generates a token in DB const resetoken = cy.task( 'queryDb', `select _Token from tokens WHERE _Member_Id = 25372 and _Token_Type = "resetPassword" ORDER BY _id DESC LIMIT 1` ) // saving the token from DB generate from above Cypress.env('token', resetoken) cy.request({ method: 'PATCH', url: 'https://xxx/xx/xx/changePasswordWithToken', body: { confirmPassword: 'xxx', password: 'xx', token: Cypress.env('token'), //passing the saved token from database uid: 1234, }, }) })
about 4 years ago · Juan Pablo Isaza Report

0

Puede guardarlo como un alias y luego acceder a él más tarde llamando al alias o usando this palabra clave dentro de function(){} en lugar de la función de flecha () => {}

 // use function{} instead of () => {} it.only('Change Password', function() { cy.ResetPassAPI(globalThis.data.dradminemail) cy.task( 'queryDb', `select _Token from tokens WHERE _Member_Id = 25372 and _Token_Type = "resetPassword" ORDER BY _id DESC LIMIT 1`,) // task returns token so we save it with alias .as('resetToken') cy.request({ method: 'PATCH', url: 'https://xxx/xx/xx/changePasswordWithToken', body: { confirmPassword: 'xxx', password: 'xx', token: this.resetToken, uid: 1234, }, }) })
about 4 years ago · Juan Pablo Isaza Report

0

Tienes una sintaxis incorrecta para cy.task()

En vez de

 const resetoken = cy.task(...)

debería ser

 cy.task(...).then(resetoken => {

Prueba completa:

 it('Change Password', () => { cy.ResetPassAPI(globalThis.data.dradminemail); const query = 'select _Token from tokens WHERE _Member_Id = 25372 and _Token_Type = "resetPassword" ORDER BY _id DESC LIMIT 1'; cy.task('queryDb', query) .then(resetoken => { cy.request({ method: 'PATCH', url: 'https://xxx/xx/xx/changePasswordWithToken', body: { confirmPassword: 'xxx', password: 'xx', token: resetoken, uid: 1234, }, }); }); });

Probablemente no necesite el token en ningún otro lugar, una vez que se haya enviado el PARCHE.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!