Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize console.log/info/warn/error to stdout on CLI runs #700

Closed
brian-mann opened this issue Oct 2, 2017 · 27 comments
Closed

Serialize console.log/info/warn/error to stdout on CLI runs #700

brian-mann opened this issue Oct 2, 2017 · 27 comments
Labels
cli stage: ready for work The issue is reproducible and in scope type: feature New feature that does not currently exist

Comments

@brian-mann
Copy link
Member

Currently there's no way to see browser messages in stdout.

We can likely serialize the console.* method calls and send them to the node process.

Users would need a way to opt into this. Perhaps just another namespace DEBUG command like.

DEBUG=cypress:console:* cypress run
DEBUG=cypress:console:log cypress run
DEBUG=cypress:console:info cypress run
DEBUG=cypress:console:warn cypress run
DEBUG=cypress:console:error cypress run
@brian-mann brian-mann added the type: feature New feature that does not currently exist label Oct 2, 2017
@brian-mann
Copy link
Member Author

Related to #448

@brian-mann brian-mann changed the title Export console.log/info/warn/error to stdout on CLI runs Serialize console.log/info/warn/error to stdout on CLI runs Oct 2, 2017
@nwshane
Copy link

nwshane commented Jun 7, 2018

@brian-mann Do you have an estimate of when this will be implemented? It's hard to debug test failures in CI without seeing the browser logs :/

@brian-mann
Copy link
Member Author

brian-mann commented Jun 7, 2018

Today you can spy on console.log with cy.spy and it will print to the Command Log as an event. Don't have a better option, but this is something we've been actively comping in the Dashboard and are working on the infra to capture + display these along with the command data, network traffic, logs, etc.

Cypress.on('window:before:load', (win) => {
  cy.spy(win.console, "log")
})

@nwshane
Copy link

nwshane commented Jun 7, 2018

@brian-mann Ah, interesting. But we don't have access to the cypress logs either, do we? Except for in the video, which doesn't allow us to view e.g. detailed JSON output.

@brian-mann
Copy link
Member Author

You have access to screenshots + video.

@lgandecki
Copy link

@nwshane I think you misunderstood, you will have access to the video and the console.logs in your CI. It won't be as perfect as watching a video with real-time matched logs, but you should be able to figure out what's going on if you purposefully left the console.logs in to debug the problem.

@arsduo
Copy link

arsduo commented Dec 6, 2018

Just spent a bunch of time today fighting with a test bug where the ability to throw a console.log into the code and see the output in STDOUT on CI would have been invaluable. Glad to see that this is in progress!

@jeremyjh
Copy link

@lgandecki can you explain how to get access to console.logs in CI? Nothing logged by the browser or by cy.log is displayed in the CLI output that I can see.

@chrishenry
Copy link

Would love to see this implemented! So much so that if there's anything I can to help build or QA this, let me know!

@jennifer-shehane

This comment has been minimized.

@folmert
Copy link

folmert commented Mar 22, 2019

Any update on this feature? Without it it's really difficult to tell why my tests which pass locally are failing in headless browser on gitlab. Being able to see browser's console errors/warnings in the terminal output would give me a great hint what's wrong in my CI environment.

@jennifer-shehane I tried https://github.com/bahmutov/cypress-failed-log but it's not relevant to this issue, it only prints cypress commands into terminal output, there is nothing about displaying browser's errors.

@flotwig
Copy link
Contributor

flotwig commented May 9, 2019

I made a Cypress plugin that prints out all console messages from the browser, including both user-created (console.log) messages and browser-created (CORS errors, etc.) messages.

It only supports Chrome so far, as I can't figure out a way to connect to Electron's Chrome Debug Protocol instance from a plugin.

Plugin here: https://github.com/flotwig/cypress-log-to-output

@Pomax
Copy link

Pomax commented May 22, 2019

Chrome only isn't super great for people using Selenium/Phantom/etc., did you test any of those @flotwig?

@flotwig
Copy link
Contributor

flotwig commented May 22, 2019

@Pomax I haven't tested that, but if your browser accepts --remote-debugging-port, that's all it needs to work.

@x-yuri
Copy link

x-yuri commented Dec 7, 2019

@flotwig Electron apps can be told to produce verbose output in a terminal (stderr) with ELECTRON_ENABLE_LOGGING=true. That includes output from console.log() statements. But for one reason or another it seems like Cypress has it enabled by default (maybe @jennifer-shehane can elaborate on this?). The reason why you don't generally see console.log statements in the terminal is because Cypress cypresses :) suppresses them by default. But you can make them visible with DEBUG=cypress:electron npx cypress .... Although some messages would still be unavailable.

@MaaikeFox
Copy link

@brian-mann , could you explain how to implement this please? I added it to a test with no result. We really need to be able to see console errors when a test fails

Cypress.on('window:before:load', (win) => { cy.spy(win.console, "log") })

@MaaikeFox
Copy link

I would also love to finally see this implemented in Cypress. It is very important for debugging failed tests, and that seems to me one of the first things a test tool should enable.

@jacob-8
Copy link

jacob-8 commented Dec 31, 2019

I've been bouncing around the different Cypress issues all related to the desire to see the browser logs printed into the CI output (issue #448 and others) and I finally found a workable solution which will spy on the console logs and errors and then print all cypress :

Step 1: Spy on console logs and errors by adding this snippet to cypress/support/index.js:

Cypress.on('window:before:load', (win) => {
    cy.spy(win.console, "log")
    cy.spy(win.console, "error")
})

Step 2: Use https://github.com/bahmutov/cypress-failed-log to print to the terminal on failed tests.

  1. Run npm install --save-dev cypress-failed-log
  2. Add require('cypress-failed-log'); to cypress/support/index.js
  3. Add to cypress/plugins/index.js:
module.exports = (on, config) => {
  on('task', {
    failed: require('cypress-failed-log/src/failed')(),
  })
};

@folmert @MaaikeFox - and others, I hope this answers your search for a solution until this is officially integrated.

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: proposal 💡 No work has been done of this issue labels Jan 2, 2020
@pshynin
Copy link

pshynin commented Jan 16, 2020

how many +1 we need to implement this ? Let all thumbs up ?

@flotwig
Copy link
Contributor

flotwig commented Jan 16, 2020

@pshynin There are available workarounds detailed above. If this is a feature you'd like to see in Cypress very soon, please feel free to open a pull request. See our contributing docs for more info.

@archfz
Copy link

archfz commented Feb 2, 2020

There is also this package for outputing verbose information in a good looking way to the terminal when tests fail. https://github.com/archfz/cypress-terminal-report It also shows data for request captured with cy.route. @flotwig could this package be added to the plugins list https://docs.cypress.io/plugins/ ?

@dananpambudi
Copy link

There is also this package for outputing verbose information in a good looking way to the terminal when tests fail. https://github.com/archfz/cypress-terminal-report It also shows data for request captured with cy.route. @flotwig could this package be added to the plugins list https://docs.cypress.io/plugins/ ?

hi may i know how do u use this plugin?

@archfz
Copy link

archfz commented Feb 11, 2020

@dananpambudi I am not sure if I understand your question.

If your asking for installation and setup then you should read the readme of the repository. If your having issues using it create an issue in the repository issue tracker.

If your asking how I personally use it, well I use it quite well to get more clues when cypress tests fail during CI in gitlab.

@dananpambudi
Copy link

thanks it works well @archfz

@flotwig
Copy link
Contributor

flotwig commented Feb 11, 2020

@flotwig could this package be added to the plugins list docs.cypress.io/plugins ?

@archfz Definitely, go ahead and open a PR in our documentation repo to add it: https://github.com/cypress-io/cypress-documentation/blob/develop/CONTRIBUTING.md#adding-plugins

@JohnnyFun
Copy link

@archfz thanks for writing cypress-terminal-report!

Fwiw, I set my defaultTrimLength to 2000, otherwise default of 200 cuts off stack property of logged errors--you might consider bumping up the default for that.

@jennifer-shehane
Copy link
Member

Closing this issue as making browser console info available for review during the run is part of Cypress Test Replay. Test Replay allows you to see all console logs, including errors, info and warnings, as they displayed when your tests ran.

If you'd like to log console output to the terminal, there are some great open source plugins available to facilitate this also like https://github.com/flotwig/cypress-log-to-output.

Thanks for all of your feedback on this issue. 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli stage: ready for work The issue is reproducible and in scope type: feature New feature that does not currently exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.