cypress-log-to-output icon indicating copy to clipboard operation
cypress-log-to-output copied to clipboard

Option to only record the logs?

Open spschlegel opened this issue 4 years ago • 9 comments

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?

spschlegel avatar Feb 10 '21 13:02 spschlegel

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

nischaytv avatar Feb 02 '22 05:02 nischaytv

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

spschlegel avatar Feb 02 '22 09:02 spschlegel

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

nischaytv avatar Feb 02 '22 10:02 nischaytv

Something like this:

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

const logs = getLogs();

spschlegel avatar Feb 03 '22 15:02 spschlegel

Something like this:

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

const logs = getLogs();

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

Arahort avatar Feb 07 '22 11:02 Arahort

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.

laviniaSer07 avatar Feb 09 '22 11:02 laviniaSer07

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.

spschlegel avatar Feb 09 '22 13:02 spschlegel

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.

Arahort avatar Feb 09 '22 15:02 Arahort

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
}

oliverstr avatar Jul 21 '22 08:07 oliverstr