Skip to content

Latest commit

 

History

History
227 lines (178 loc) · 5.76 KB

README.md

File metadata and controls

227 lines (178 loc) · 5.76 KB

allure-cypress

Allure framework integration for Cypress

Allure Report logo


Installation

Use your favorite node package manager to install the required packages:

npm add -D allure-cypress

Add the following lines to your cypress.config.js file to setup the reporter:

const { allureCypress } = require("allure-cypress/reporter");

module.exports = {
  // ...
  e2e: {
+    setupNodeEvents: (on, config) => {
+      allureCypress(on, {
+        resultsDir: "./allure-results",
+      });
+
+      return config;
+    },
  },
};

Don't forget to add the Allure Cypress commands to your cypress/support/e2e.js file to finish the installation:

+ import "allure-cypress";

Use Allure runtime Api

The plugin provides custom commands which allow to add additional info inside your tests:

import { epic, attachment, parameter } from "allure-js-commons";

it("my test", () => {
  attachment("Attachment name", "Hello world!", "text/plain");
  epic("my_epic");
  parameter("parameter_name", "parameter_value", {
    mode: "hidden",
    excluded: false,
  });
});

Links usage

import { link, issue, tms } from "allure-js-commons";

it("basic test", () => {
  link("link_type", "https://allurereport.org", "Allure Report");
  issue("Issue Name", "https://github.com/allure-framework/allure-js/issues/352");
  tms("Task Name", "https://github.com/allure-framework/allure-js/tasks/352");
});

You can also configure links formatters to make usage much more convenient. %s in urlTemplate parameter will be replaced by given value.

const { allureCypress } = require("allure-cypress/reporter");

module.exports = {
  // ...
  e2e: {
    setupNodeEvents: (on, config) => {
      allureCypress(on, {
+        links: [
+          {
+            type: "issue",
+            urlTemplate: "https://example.org/issues/%s",
+            nameTemplate: "Issue: %s",
+          },
+          {
+            type: "tms",
+            urlTemplate: "https://example.org/tasks/%s"
+          },
+          {
+            type: "custom",
+            urlTemplate: "https://example.org/custom/%s"
+          },
+        ],
+      });

      return config;
    },
  },
};

Then you can assign link using shorter notation:

import { link, issue, tms } from "allure-js-commons";

it("basic test", () => {
  issue("351");
  issue("352", "Issue Name");
  tms("351");
  tms("352", "Task Name");
  link("custom", "352");
  link("custom", "352", "Link name");
});

Steps usage

The integration supports Allure steps, use them in following way:

import { step } from "allure-js-commons";

it("my test", () => {
  step("foo", () => {
    step("bar", () => {
      step("baz", () => {
        cy.log("my cypress commands");
      });
    });
  });
});

Passing metadata from test title

You also can pass allure metadata from test title. This is useful when you need to set allureId for the tests with failing before hooks. Just add @allure.id={idValue} for the allureId or @allure.label.{labelName}={labelValue} for other types of labels.

it("test with allureId @allure.id=256", () => {});
it("tst with severity @allure.label.severity=critical", () => {});
it("test with epic @allure.label.epic=login", () => {});
it("test with strangeLabel @allure.label.strangeLabel=strangeValue", () => {});

Warning Note that changing title can cause creating new testcases in history. To fix this please add @allure.id={yourTestCaseId} to the test name if you passing allure metadata from test title

Using custom after:run hook

If you want to use your own after:run hook and keep the Allure reporter working, you should use AllureCypress class instead:

const { AllureCypress } = require("allure-cypress/reporter");

module.exports = {
  // ...
  e2e: {
    setupNodeEvents: (on, config) => {
+      const allureCypress = new AllureCypress({
+        resultsDir: "./allure-results",
+      });
+      
+      allureCypress.attachToCypress(on, config);
+ 
+      on("after:run", (results) => {
+        allureCypress.endRun(results);
+      });
+  
+      return config;
+    },
  },
};

Write video attachments for failed tests only

If you want to see Cypress videos only for failed or broken tests in your Allure report, you can use the videoOnFailOnly option:

const { allureCypress } = require("allure-cypress/reporter");

module.exports = {
  // ...
  e2e: {
+    video: true,
    setupNodeEvents: (on, config) => {
      allureCypress(on, {
+        videoOnFailOnly: true,
      });

      return config;
    },
  },
};

Known issues

Global hooks reporting

The integration can't report after hooks properly defined outside of the describe block. If you want to see the hooks in the report wrap your tests into describe block and move the hooks inside it:

// this hook won't be reported
after(() => {})

describe("suite", () => {
  // this hook will be reported
  after(() => {})

  it("test", () => {})
})