Is it possible to redirect or capture Cypress browser log and command log to output?
I read some Cypress github issues on this topic. But I don\'t know how to make
FYI:
Cypress community is going to provide native support so that we don't have to do any workarounds to print the logs on non-GUI(headless) CLI.
Ongoing issue: https://github.com/cypress-io/cypress/issues/448
Expanding on @Joshua-wade's answer, you can overwrite cy.log
to redirect all calls to it to the log task. Just as the following:
Cypress.Commands.overwrite('log', (subject, message) => cy.task('log', message));
Note: there's a small drawback to this: when you run the test using the Test Runner, instead of seeing LOG my message
in the command log, you'll see TASK log, my message
. But IMHO it's negligible.
As of Cypress 3.0.0, you can use cy.task()
to access node directly and output to the node console. From the docs:
// in test
cy.task('log', 'This will be output to the terminal')
// in plugins file
on('task', {
log (message) {
console.log(message)
return null
}
})
See here for more info.
I don't know of a way to mirror the Cypress logs to the console directly, but this is at least a workable alternative.