I have a custom command in my tests to record requ...
# e2e-testing
a
I have a custom command in my tests to record requests, here's a few bits of it that might help you -
Copy code
cy.intercept(cyInterceptArgs, request => {
  request.on('before:response', response => {
    // using env is super odd, but this is how to mix sync / async cy.task / cy.command code
    // https://filiphric.com/working-with-api-response-data-in-cypress
    Cypress.env('response', response)
  })

  request.continue()
}).as(url)
Then further down after some
fsReadFile
logic,
Copy code
const response = Cypress.env('response') || null
if (file.shouldRecord && response) {
  cy.writeFile(filePath, response)
}
You can save the request/event data into the
Cypress.env('response')
, then access it later.