Cypress pipe console.log and command log to output

前端 未结 3 1317
再見小時候
再見小時候 2020-12-31 04:17

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

相关标签:
3条回答
  • 2020-12-31 04:48

    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

    0 讨论(0)
  • 2020-12-31 04:52

    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.

    0 讨论(0)
  • 2020-12-31 05:04

    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.

    0 讨论(0)
提交回复
热议问题