New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

allure-cucumberjs

Package Overview
Dependencies
Maintainers
0
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allure-cucumberjs

Allure Cucumber.JS integration

  • 3.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
decreased by-18.76%
Maintainers
0
Weekly downloads
 
Created
Source

allure-cucumberjs

Allure integration for cucumber-js compatible with @cucumber/cucumber@^8.x.x and Allure 2+.

Allure Report logo


Installation

Install the required packages using your favorite package manager:

npm add -D allure-cucumberjs

Create reporter.js with following content:

// reporter.js
const AllureCucumberReporter = require("allure-cucumberjs/reporter");

export default AllureCucumberReporter;

Then add following lines to the CucumberJS configuration file:

// config.js
export default {
+  format: "./path/to/reporter.js",
};

And then run CLI with config parameter:

cucumber-js --config ./config.js

Reporter options

Some reporter settings can be set by following options:

OptionDescriptionDefault
resultsDirPath to results folder./allure-results
linksLinks templates to make runtime methods calls simpler and process Cucumber tags as Allure linksundefined
labelsLabels templates to process Cucumber tags as Allure labelsundefined

Using Allure API

To start using Allure Runtime API you need to add the following import into your ./feature/support/world.js file:

import "allure-cucumberjs";

Then, you can call Allure Runtime API methods directly in your step definitions:

import { Given } from "@cucumber/cucumber";
import { label, attachment, step } from "allure-js-commons";

Given(/my step/, async () => {
  await step("step can have anonymous body function", async () => {
    await label("label_name", "label_value");
    await attachment(JSON.stringify({ foo: "bar " }), "application/json");
  });

  await step("by the way, body function can be arrow one", async () => {
    await label("label_name", "label_value");
    await attachment(JSON.stringify({ foo: "bar " }), "application/json");
  });
});

Using Allure Cucumber World

If you prefer to use custom Allure World instead of global Allure API, you can use AllureCucumberWorld class:

import { AllureCucumberWorld } from "allure-cucumberjs";
import { setWorldConstructor } from "@cucumber/cucumber";

setWorldConstructor(AllureCucumberWorld);

Then you'll be able to use Allure Runtime API through this in your step definition files:

import { Given } from "@cucumber/cucumber";

Given(/my step/, async function() {
  const self = this;
  
  await self.step("step can have anonymous body function", async function() {
    await self.label("label_name", "label_value");
    await self.attachment(JSON.stringify({ foo: "bar " }), "application/json");
  });

  await self.step("by the way, body function can be arrow one", async function() {
    await self.label("label_name", "label_value");
    await self.attachment(JSON.stringify({ foo: "bar " }), "application/json");
  });
});

If you run your Cucumber features using single thread mode, AllureCucumberWorld is set automatically.

const { Given } = require("@cucumber/cucumber");
import { link, issue, tms } from "allure-js-commons";

Given("step name", async () => {
  await link("link_type", "https://allurereport.org", "Allure Report");
  await issue("Issue Name", "https://github.com/allure-framework/allure-js/issues/352");
  await 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.

// config.js
export default {
  format: "./path/to/reporter.js",
+  formatOptions: {
+    links: [
+      {
+        pattern: [/@issue=(.*)/],
+        type: "issue",
+        urlTemplate: "https://example.com/issues/%s",
+        nameTemplate: "Issue: %s",
+      },
+      {
+        pattern: [/@tms=(.*)/],
+        type: "tms",
+        urlTemplate: "https://example.com/tasks/%s",
+      },
+    ],
+  }
};

Then you can assign link using shorter notation:

const { Given } = require("@cucumber/cucumber");
import { link, issue, tms } from "allure-js-commons";

Given("step name", async () => {
  await issue("351");
  await issue("352", "Issue Name");
  await tms("351");
  await tms("352", "Task Name");
  await link("custom", "352");
  await link("custom", "352", "Link name");
});

Links patterns also work with Cucumber tags which match pattern parameter:

@issue=0
Feature: links

  @issue=1 @tms=2
  Scenario: a
    Given a step

Parameters usage

import { Given } from "@cucumber/cucumber";
import { step, parameter } from "allure-js-commons";

Given(/my step/, async () => {
  await step("step can have anonymous body function", async () => {
    await parameter("parameterName", "parameterValue");
  });
});

Also addParameter takes an third optional parameter with the hidden and excluded options:

mode: "hidden" | "masked" - masked hide parameter value to secure sensitive data, and hidden entirely hide parameter from report

excluded: true - excludes parameter from the history

import { Given } from "@cucumber/cucumber";
import { step, parameter } from "allure-js-commons";

Given(/my step/, async () => {
  await step("step can have anonymous body function", async () => {
    await parameter("parameterName", "parameterValue", { mode: "hidden", excluded: true });
  });
});

Cross-browser testing

For cross-browser testing simply add a parameter using Allure API with the browser name to the World instance inside your scenario, i.e.:

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

await parameter('Browser', 'firefox')

For better presentation, you can also group suites by browser names, i.e.:

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

await parentSuite('Firefox')

FAQs

Package last updated on 02 Oct 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc