output the cypress browser log messages when running headless in CI

Viewed 490

I am using cypress-io and cypress-axe to run browser tests and check if a page has accessibility violations.

I have this task:

function reportA11yViolations(violations: Result[]) {
  const errors: string[] = [];

  violations.forEach((v: Result) => v.nodes.forEach((node: NodeResult) => {
    errors.push(node.failureSummary);
  }));

  cy.log(errors.join("\n"));
}

Cypress.Commands.add("checkA11yAndReportViolations", (context, options) => {
  cy.checkA11y(context, options, reportA11yViolations);
});

I can see all the browser log messages when running through the nice browser app.

But what about when I am running in headless in the ci environment?

Is there anyway I can display these errors anywhere or write them to a file?

1 Answers

You can output the cypress logs to a file

cy.writeFile('accessibilityReport.txt', `${node.failureSummary} \n`, { flag: 'a+' });

a+ will append the result to the file. The build artifacts of the jenkins pipeline should have the report thus created.

Related