Allure Cucumber.js reference
These are the functions that you can use to integrate your Cucumber.js tests with Allure.
Note that if you are going to run your tests in parallel, it is necessary to use the Allure's implementation of the world environment for Cucumber.js to support all the features. To do so, add this to the beginning of each JavaScript file in your Cucumber.js tests:
JavaScriptconst { setWorldConstructor } = require("@cucumber/cucumber");
const { CucumberAllureWorld } = require("allure-cucumberjs");
if (process.env.PARALLEL) {
setWorldConstructor(CucumberAllureWorld);
}
// ...
Metadata
Assign a test's description, links and other metadata.
Description
this.description(markdown: string)
Set the test's description. Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.description(
"This test attempts to log into the website using a login and a password. Fails if any error happens.\n\n" +
"Note that this test does not test 2-Factor Authentication.",
);
// ...
});
Owner
this.owner(owner: string)
Set the test's owner.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.owner("John Doe");
// ...
});
Tag
this.tag(tag: string)
Set the test's tags.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.tag("NewUI");
this.tag("Essentials");
this.tag("Authentication");
// ...
});
Severity
this.severity(severity: string)
Set the test's severity.
The value must be a constant from the Severity
class.
JavaScriptconst { Then } = require("@cucumber/cucumber");
const { Severity } = require("allure-js-commons");
Then("do something", async function () {
this.severity(Severity.CRITICAL);
// ...
});
Label
this.label(label: string, value: string)
Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.
You can call the function multiple times to create an array of values under that name.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.label("language", "javascript");
this.label("framework", "cucumberjs");
// ...
});
ID
this.id(allureId: string)
Set the test's ID.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.id("123");
// ...
});
Link
this.link(url: string, name?: string, type?: string)
Add a link related to the test.
The name
will be used as the link's text. If it is omitted, the full URL will be used instead.
The type
affects the icon that is displayed next to the link in the test report. For convenience, Allure provides two shorthand functions with pre-selected link types: issue()
and tms()
.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.link("https://example.com/docs", "Related Documentation");
this.issue("https://example.com/issues/AUTH-123", "AUTH-123");
this.tms("https://example.com/tms/TMS-456", "TMS-456");
// ...
});
Issue
this.issue(name: string, url: string)
Add a link to an issue in a bug tracker related to the test.
This is a shorthand for link()
with the "issue"
type.
TMS
this.tms(name: string, url: string)
Add a link to an issue in a bug tracker related to the test.
This is a shorthand for link()
with the "tms"
type.
Behavior-based hierarchy
this.epic(epic: string)
this.feature(feature: string)
this.story(story: string)
Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.
Suite-based hierarchy
this.suite(name: string)
this.parentSuite(name: string)
this.subSuite(name: string)
Assign names of parent suite, suite or sub-suite for a test, as part of Allure's suite-based hierarchy.
Test steps
step()
await this.step(name: string, body: StepBodyFunction)
Define a test sub-step with the given name
. The body must be a function, either synchronous or asynchronous, implementing the logic of the sub-step.
Note that within each sub-step, this
points to its own sub-step object. It has the same functions, but does not store properties previously added into the outer step's this
. For this reason, you may have to create a local variable to access such a property.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
await this.step("Step 1", async function () {
// ...
});
await this.step("Step 2", async function () {
await this.step("Step 2.1", async function () {
// ...
});
await this.step("Step 2.2", async function () {
// ...
});
});
});
Parametrized tests
this.parameter(name: string, value: string, options?: ParameterOptions)
Specify a name
and value
of a parameter that was used during this test. See Parametrized tests for more details.
The options
argument, if given, must be an object with two optional properties excluded
and mode
.
If
excluded
is set to true, Allure will not use the parameter when comparing the current test result with previous one in the history.The
mode
affects how the parameter will be displayed in the report. Available options are:"default"
(same as not specifying any mode) — the parameter and its value will be shown in a table along with other parameters."masked"
— the parameter will be shown in the table, but its value will be hidden. Use this mode for passwords, tokens and other sensitive parameters."hidden"
— the parameter and its value will not be shown in the test report. Note, however, that it is still possible to extract the value from theallure_results
directory if you publish it.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
this.parameter("auth_method", "password");
this.parameter("login", "johndoe");
// ...
});
Attachments
this.attach(content: string | Buffer, type: string)
Add content
as an attachment to the test result. The content can be a text string or a base64-encoded Buffer
.
You can use data produced by any function, not necessarily read from an actual file.
To ensure that the reader's web browser will display attachments correctly, it is recommended to specify each attachment's type. To do so, pass the MIME type of the content as type
.
JavaScriptconst { Then } = require("@cucumber/cucumber");
Then("do something", async function () {
let browser = await chromium.launch();
let page = await browser.newPage();
await page.goto("https://example.com/");
let screenshot = await page.screenshot();
this.attach(screenshot, "image/png");
await page.close();
await browser.close();
});