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

Console messages not working? #67

Closed
andrei1015 opened this issue Dec 1, 2020 · 7 comments
Closed

Console messages not working? #67

andrei1015 opened this issue Dec 1, 2020 · 7 comments

Comments

@andrei1015
Copy link

Hello! I am trying to make console.log to show in the terminal but until now I've only managed to see cy.log. Cypress is still at version 5.5.0 and I;ve set the plugin to always display.

Tried console.log both in a test and outside, in a helper file.

@archfz
Copy link
Owner

archfz commented Dec 1, 2020

Please provide the plugin version and the options you are using on the collector install.

@andrei1015
Copy link
Author

Have just updated to the latest version of the plugin and rechecked.

The plugin installation:

module.exports = (on, config) => {
  let config = {};
  config.printLogsToConsole = 'always';
  require('cypress-terminal-report/src/installLogsPrinter')(on, config);
};

And the support installation:

let config = {};
config.collectTypes = ['cons:log', 'cons:info', 'cons:warn', 'cons:error', 'cy:log'];
require('cypress-terminal-report/src/installLogsCollector')(config);

And in the code I have:

    console.log('help');
    console.info('help');
    console.warn('help');
    console.error('help');
    cy.log('help');

This is in a spec file, also tried from a helper file. Only the cy.log one seems to work.

@archfz
Copy link
Owner

archfz commented Dec 1, 2020

You shouldnt be using console logging in test code. Use cy.log there. The console logs only appear from your application that is tested. Cypress test execution is in primary browser frame and your site being tested is running in a child frame (iframe), only in the later we intercept console logging.

@archfz archfz closed this as completed Dec 1, 2020
@archfz
Copy link
Owner

archfz commented Dec 1, 2020

If for some reason you still want to use console log in test code do: cy.window().then(w => w.console.log()). Mainly it is not advised to use console log in test code for cypress since cypress uses a queue (async) to execute stuff in order, and plain console.log is sync.

@nicholaschiang
Copy link

@archfz Is this documented in the README somewhere? I couldn't see it and thus assumed I could use console.log and it would be recorded automatically.

@archfz
Copy link
Owner

archfz commented Mar 27, 2021

No it's not documented. Let s add it in that case.

@archfz archfz reopened this Mar 27, 2021
@archfz
Copy link
Owner

archfz commented Mar 27, 2021

Released in 3.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants