Giter Site home page Giter Site logo

cypress-log-to-output's Introduction

cypress-log-to-output

This is a Cypress plugin that sends all console logs that occur in the browser to stdout in the terminal. This means that you can see any kind of console.log, console.info or console.error that occurs in the browser, even if your tests are running in the terminal.

Installation

npm install --save-dev cypress-log-to-output

Usage

In your cypress/plugins/index.js, add this to your module.exports:

module.exports = (on, config) => {
  /** the rest of your plugins... **/
  require('cypress-log-to-output').install(on)
  // or, if there is already a before:browser:launch handler, use .browserLaunchHandler inside of it
  // @see https://github.com/flotwig/cypress-log-to-output/issues/5
}

You'll now see all browser console logs in your terminal output.

cypress run --browser=chrome

Screen Shot 2019-05-20 at 3 01 12 PM

Works in Chrome, Chromium, or Canary browsers during cypress run and cypress open.

Electron is not currently supported. I can't find a way to attach the Chrome Debugging Protocol to the Electron browser spawned by Cypress.

Filtering Events

If you want to filter events, you can use a custom filtering callback:

module.exports = (on, config) => {
  /** the rest of your plugins... **/
  require('cypress-log-to-output').install(on, (type, event) => {
    // return true or false from this plugin to control if the event is logged
    // `type` is either `console` or `browser`
    // if `type` is `browser`, `event` is an object of the type `LogEntry`:
    //  https://chromedevtools.github.io/devtools-protocol/tot/Log#type-LogEntry
    // if `type` is `console`, `event` is an object of the type passed to `Runtime.consoleAPICalled`:
    //  https://chromedevtools.github.io/devtools-protocol/tot/Runtime#event-consoleAPICalled

    // for example, to only show error events:

    if (event.level === 'error' || event.type === 'error') {
      return true
    }

    return false
  })
}

Disabling debug info

You can remove the lines beginning with [cypress-log-to-output] by passing -cypress-log-to-output in the DEBUG environment variable.

cypress-log-to-output's People

Contributors

flotwig avatar arsduo avatar jennifer-shehane avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.