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

220
Vistas
How to list and record all network requests and response times in Cypress

I am looking to convert all requests from cy.intercept() into json objects that include: {'method':'____', 'url':'____', 'response_time':'____'} so that they can be written to a json file for performance analysis.

I am currently able to show all of the request methods and URL's but not their response times.

Current code to get network requests:

cy.intercept({method:'GET', url:'**'}).as('gets');
cy.intercept({method:'POST', url:'**'}).as('posts');
cy.visit('url');

Is it possible to iterate through these individual requests with their response times and save them within an array?

I have tried saving the value returned from intercept() as a variable but it doesn't show all of the requests or their response times.

var gets = cy.intercept({method:'GET', url:'**'}).as('gets');
var posts = cy.intercept({method:'POST', url:'**'}).as('posts');
cy.visit('url');

cy.writefile('file1.json', gets);
cy.writefile('file2.json', posts);

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You want to use cy.intercept() callbacks to get the duration.

The request callback fires when the request is intercepted, and the response callback is fired when the reponse returns.

const gets = []

const logGet = (request) => {
  const start = Date.now()
  request.continue((response) => {
    const duration = Date.now() - start
    gets.push({url: request.url, duration})
  })
}

cy.intercept('*', logGet)

cy.intercept('**/tracking.min.js').as('done')           // last call I'm interested in

cy.visit('https://docs.cypress.io/api/commands/intercept')

cy.wait('@done').then(() => {                          // wait for last
  console.log(gets)
})

Also, chose a network request that marks the end on the stream. Cypress does not know when calls have ended, so you should cy.wait() on the last one instead of wait(3000).

In above example, I chose the Cypress tracking script.

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