2

I'd like to print arbitrary outputs to the terminal per each test after calling cypress run. The outputs should appear regardless of each test's success/failure. I've followed the instructions from dozens of online answers - nothing worked for me.

I'm using Cypress 8.7.0. Thanks!

nozik
  • 307
  • 1
  • 12
  • 2
    It would be helpful if you could add a few online answers you have tried. – jjhelguero Apr 05 '22 at 17:35
  • A few examples: https://stackoverflow.com/questions/52070262/cypress-pipe-console-log-and-command-log-to-output https://stackoverflow.com/questions/55303738/cypress-how-to-print-tested-apps-console-errors-into-terminal-output https://github.com/cypress-io/cypress/issues/3199 Not sure how this helps though. – nozik Apr 08 '22 at 07:39

1 Answers1

2

It's pretty much what @nozik linked to. In your cypress.config.js add:

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('task', {
        log(message) {
          // Then to see the log messages in the terminal
          //   cy.task("log", "my message");
          console.log(message +'\n\n');
          return null;
        },
      });
    },
  },
});

which can then be called in your tests with:

    cy.task('log', 'Display some logging');

colin0117
  • 1,448
  • 1
  • 11
  • 15