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

Option to only record the logs? #18

Open
spschlegel opened this issue Feb 10, 2021 · 9 comments · May be fixed by #20
Open

Option to only record the logs? #18

spschlegel opened this issue Feb 10, 2021 · 9 comments · May be fixed by #20

Comments

@spschlegel
Copy link

spschlegel commented Feb 10, 2021

Its great being able to record the console logs in addition to printing them to the terminal.
I would like to store the logs during the cypress tests for our CI builds but printing them to the terminal output as well is flooding the output.
Is there a way to only record the logs and not print them to the terminal output?

@Narretz Narretz linked a pull request Sep 27, 2021 that will close this issue
@nischaytv
Copy link

How can we retrieve the recorded logs. Is it possible to store these logs in a file? If yes how can this be done?

@spschlegel
Copy link
Author

From the Readme:
The logs will be stored in an internal buffer. They can be accessed using the getLogs exported function. The buffer can be cleared using the clearLogs exported function.

So we used the getLogs function to retrieve the logs and then wrote them to a file using fs.createWriteStream

@nischaytv
Copy link

Do you have any code sample for this? I tried using getLogs, but didn't get it.

@spschlegel
Copy link
Author

Something like this:

import {
  getLogs
} from 'cypress-log-to-output';

const logs = getLogs();

@Arahort
Copy link

Arahort commented Feb 7, 2022

Something like this:

import {
  getLogs
} from 'cypress-log-to-output';

const logs = getLogs();

May be stupid question, but how use this in test step?

@laviniaSer07
Copy link

Something like this:

import {
  getLogs
} from 'cypress-log-to-output';

const logs = getLogs();

May be stupid question, but how use this in test step?

I'm also interested about how to use it in a test step.

@spschlegel
Copy link
Author

I don't think I really understand what you want to do.
Using this is not tied to tests in general.
You import the getLogs function and then you call it whenever you want to retrieve the current logs.
You will get them as an array and then it's up to you to do something with that array.

@Arahort
Copy link

Arahort commented Feb 9, 2022

I don't think I really understand what you want to do.
Using this is not tied to tests in general.
You import the getLogs function and then you call it whenever you want to retrieve the current logs.

Then test crashed, and cypress-log-to-output - breaks other packages, such as cypress-audit. I had to remove it altogether so that the rest of the packages would work again.

@oliverstr
Copy link

Something like this:

import {
  getLogs
} from 'cypress-log-to-output';

const logs = getLogs();

May be stupid question, but how use this in test step?

The plugin and your spec file run in different environments, to access the node process from your test spec you need to use cy.task.

When installing the plugin, add:

import { getLogs, install } from 'cypress-log-to-output';

module.exports = (on, config) => {
  /** the rest of your plugins... **/
  const options = { recordLogs: true };
  install(on, filterCallback, options);
  
  on('task', {
     getDebuggerLogs(){
         return getLogs();
     }
  });
}

Then on your spec file access it:

cy.task('getDebuggerLogs').then((logs) => {
   // do whatever with the logs here
}

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

Successfully merging a pull request may close this issue.

5 participants