able-monkey-72947
07/18/2022, 8:20 PMcy.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,
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.