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

Integration with cypress-multi-reporters #280

Closed
hugo-gc opened this issue Dec 20, 2023 · 2 comments
Closed

Integration with cypress-multi-reporters #280

hugo-gc opened this issue Dec 20, 2023 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@hugo-gc
Copy link

hugo-gc commented Dec 20, 2023

Is it possible to use this plugin along with any other reporter using cypress-multi-reporters? If so, could you provide an example for the set up? In my case, I need to generate a mochawesome html report.

@csvtuda csvtuda self-assigned this Dec 20, 2023
@csvtuda csvtuda added the help wanted Extra attention is needed label Dec 20, 2023
@csvtuda
Copy link
Contributor

csvtuda commented Dec 20, 2023

Hey @hugo-gc,

yes, this is possible. You will need to install the following packages

npm i --save-dev cypress-multi-reporters cypress-mochawesome-reporter mocha-junit-reporter cypress-on-fix

Important

Why cypress-on-fix? Because if you're using multiple plugins/registering multiple event handlers to Cypress's on() function, the last one to register always overwrites the previously registered ones (see cypress-io/cypress#22428). In this case, both the cypress-xray-plugin and the cypress-mochawesome-reporter register themselves for 'after:run' and so on. This neat little package solves the issue and allows attaching multiple hooks to the same events.


Here is what a somewhat minimal configuration could look like:

cypress.config.ts:

import { defineConfig } from "cypress";
import { addXrayResultUpload, configureXrayPlugin } from "cypress-xray-plugin";

export default defineConfig({
  reporter: "cypress-multi-reporters",
    reporterOptions: {
      reporterEnabled: "cypress-mochawesome-reporter, mocha-junit-reporter",
      cypressMochawesomeReporterReporterOptions: {
        charts: true,
        reportDir: "cypress/reports/mochawesome",
      },
      mochaJunitReporterReporterOptions: {
        mochaFile: "cypress/reports/junit/results-[hash].xml",
      },
    },
    e2e: {
    async setupNodeEvents(on, config) {
      const fixedOn = require("cypress-on-fix")(on);
      // https://www.npmjs.com/package/cypress-mochawesome-reporter
      require("cypress-mochawesome-reporter/plugin")(fixedOn);
      // https://qytera-gmbh.github.io/projects/cypress-xray-plugin/section/setup/installation
      await configureXrayPlugin(config, {
        jira: {
          projectKey: "CYP",
          url: "https://myorg.atlassian.net",
          testExecutionIssueSummary: `Execution ${new Date().toLocaleString()}`,
        },
        xray: {
          uploadResults: true,
        },
      });
      await addXrayResultUpload(fixedOn);
    },
  },
});

cypress/support/e2e.js

// https://www.npmjs.com/package/cypress-mochawesome-reporter
import "cypress-mochawesome-reporter/register";
import "./commands";

cypress/e2e/spec.cy.ts

describe("template spec", () => {
  // https://qytera-gmbh.github.io/projects/cypress-xray-plugin/section/guides/targetingExistingIssues/
  it("CYP-529 passes", () => {
    cy.visit("https://example.org");
  });
});

When I run this project using my Jira/Xray authentication data:

CYPRESS_JIRA_USERNAME=abc@def.com \
CYPRESS_JIRA_API_TOKEN=secret123 \
CYPRESS_XRAY_CLIENT_ID=id \
CYPRESS_XRAY_CLIENT_SECRET=secret456 \
npx cypress run

I get:

  • a beautiful report in cypress/e2e/reports/mochawesome/:

    grafik

  • a JUnit XML file in cypress/e2e/reports/junit:

    grafik

  • an execution issue in Jira:

    grafik


I hope this is what you were looking for.

@csvtuda csvtuda added the awaiting feedback The issue has been addressed and the repoter's feedback is requested label Dec 20, 2023
@hugo-gc
Copy link
Author

hugo-gc commented Dec 20, 2023

Hi @csvtuda
That's exactly what I needed, it works just fine.

Thanks!

@hugo-gc hugo-gc closed this as completed Dec 20, 2023
@csvtuda csvtuda removed the awaiting feedback The issue has been addressed and the repoter's feedback is requested label Dec 20, 2023
@csvtuda csvtuda changed the title Multiple reporters Integration with cypress-multi-reporters Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants