Socket
Socket
Sign inDemoInstall

allure-cypress

Package Overview
Dependencies
8
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    allure-cypress

Allure Cypress integration


Version published
Maintainers
1
Install size
873 kB
Created

Readme

Source

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/commands";

Use Allure runtime Api

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

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

it("my test", () => {
  attachment("Attachment name", "Hello world!", "text/plain");
  epic("my_epic");
  parameter("parameter_name", "parameter_value", {
    mode: "hidden",
    excluded: false,
  });
});
import { link, issue, tms } from "allure-cypress";

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) => {
      const reporter = allureCypress(on, {
+        links: [
+          {
+            type: "issue",
+            urlTemplate: "https://example.org/issues/%s"
+          },
+          {
+            type: "tms",
+            urlTemplate: "https://example.org/tasks/%s"
+          },
+          {
+            type: "custom",
+            urlTemplate: "https://example.org/custom/%s"
+          },
+        ],
+      });

      on("after:spec", (spec, result) => {
        reporter.endSpec(spec, result);
      });

      return config;
    },
  },
};

Then you can assign link using shorter notation:

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

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-cypress";

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:spec hook

If you want to use your own after:spec 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:spec", (spec, result) => {
+        allureCypress.endSpec(spec, result);
+      });     
+  
+      return config;
+    },
  },
};

Keywords

FAQs

Last updated on 08 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc