How to see fetch history and logs after cypress run

Viewed 1456

As a part of my CI pipeline, I am testing my frontend using cypress. I run cypress run to test. One test is failing due to failed fetch request. How can I see detailed information about that fetch? So far I could only see which fetch failed from the video recording and screenshots of the test.

2 Answers

Cypress is built using the debug module. That means you can receive helpful debugging output by running Cypress with this turned on.

DEBUG=cypress:* npx cypress run

In case you want specific detailed Debug Logs, You can write something like:

DEBUG=cypress:network:*,cypress:net-stubbing* npx cypress run

Cypress is built from multiple packages, each responsible for its own logging: server, reporter, driver, command line, etc. Each package writes debug logs under a different source. You can find the list of log sources from here.

Do you know the failed url? If so, intercept it.

cy.intercept('/url', (req) => {
  req.on('response', (res) => {
    console.log(res)
  })
})

You may have difficulty with nested details, if so

console.log(JSON.stringify(res))

or

cy.writeFile('cypress/debug/fetch.json', res))
Related