e2e testing – Cypress pipe console.log and command log to output
e2e testing – Cypress pipe console.log and command log to output
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 dont know of a way to mirror the Cypress logs to the console directly, but this is at least a workable alternative.
Setting the ELECTRON_ENABLE_LOGGING
environment variable to 1
will cause all Chrome internal logging to be printed to the console.
ELECTRON_ENABLE_LOGGING=1 npx cypress run
ELECTRON_ENABLE_LOGGING
Prints Chromes internal logging to the console.
With this enabled, in addition to capturing any existing logging, this will also allow you to manually log within a test using console.log
:
console.log(Response JSON: + json)
e2e testing – Cypress pipe console.log and command log to output
Expanding on @Joshua-wades 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: theres a small drawback to this: when you run the test using the Test Runner, instead of seeing LOG my message
in the command log, youll see TASK log, my message
. But IMHO its negligible.