Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing output to terminal from 'cypress run'

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!

like image 904
nozik Avatar asked Sep 15 '25 16:09

nozik


1 Answers

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');

like image 60
colin0117 Avatar answered Sep 18 '25 11:09

colin0117