Allure CodeceptJS reference

These are the functions that you can use to integrate your CodeceptJS tests with Allure Report.

In most cases, you need to indicate to Allure CodeceptJS that a certain property needs to be assigned to the test result. Most properties can be assigned via Gherkin tags or via the Runtime API.

  • Tags API: use the tag() method to assign various data to a particular scenario.

    Most of the tags require values. You can use either a colon or an equal sign to separate the value from the name, e.g., @allure.label.epic:WebInterface is identical to @allure.label.epic=WebInterface. Note that due to a limitation in the tags syntax, the value cannot contain spaces.

    When using this approach, the data is guaranteed to be added to the test result regardless of how the test itself runs.

  • Runtime API: use Allure's functions to add data to the test result during the execution of its steps. This approach allows for constructing the data dynamically.

    Note that it is recommended to call the Allure's functions as close to the beginning of the test as possible. This way, the data will be added even if the test fails early.

Metadata

Assign a test's description, links and other metadata.

Description

  • allure.description(markdown: string): Promise<void>

Set the test's description. Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.description("This test attempts to log into the website."); // ... });

Owner

  • allure.owner(owner: string): Promise<void>
  • @allure.label.owner:⟨VALUE⟩

Set the test's owner.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.owner("John Doe"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }).tag("@allure.label.owner:JohnDoe");

Tag

  • allure.tag(tag: string): Promise<void>
  • allure.tags(...values: string[]): Promise<void>
  • @allure.label.tag:⟨VALUE⟩

Set the test's tags.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.tags("Web interface", "Authentication"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }) .tag("@allure.label.tag:WebInterface") .tag("@allure.label.tag:Authentication");

Severity

  • allure.severity(severity: string): Promise<void>
  • @allure.label.severity:⟨VALUE⟩

Set the test's severity.

Allowed values are: “trivial”, “minor”, “normal”, “critical”, and “blocker”.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.severity("critical"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }).tag("@allure.label.severity:critical");

Label

  • allure.label(name: string, value: string): Promise<void>
  • @allure.label.⟨NAME⟩:⟨VALUE⟩

Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.

The first argument of the function is the label name. It can be any string.

You can call label() multiple times to create an array of values under the given name.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.label("my custom label", "value"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }).tag("@allure.label.MyCustomLabel:value");

ID

  • allure.id(allureId: string): Promise<void>
  • @allure.id:⟨VALUE⟩

Set the test's ID.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.id("123"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }).tag("@allure.id:123");
  • allure.link(url: string, name?: string, type?: string): Promise<void>
  • allure.issue(name: string, url: string): Promise<void>
  • allure.tms(name: string, url: string): Promise<void>

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.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.link("https://dev.example.com/", "Website"); await allure.issue("AUTH-123", "https://issues.example.com/AUTH-123"); await allure.tms("TMS-456", "https://tms.example.com/TMS-456"); // ... });

Behavior-based hierarchy

  • allure.epic(epic: string): Promise<void>
  • allure.feature(feature: string): Promise<void>
  • allure.story(story: string): Promise<void>
  • @allure.label.epic:⟨VALUE⟩
  • @allure.label.feature:⟨VALUE⟩
  • @allure.label.story:⟨VALUE⟩

Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.epic("Web interface"); await allure.feature("Essential features"); await allure.story("Authentication"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }) .tag("@allure.label.epic:WebInterface") .tag("@allure.label.feature:EssentialFeatures") .tag("@allure.label.story:Authentication");

Suite-based hierarchy

  • allure.parentSuite(name: string): Promise<void>
  • allure.suite(name: string): Promise<void>
  • allure.subSuite(name: string): Promise<void>
  • @allure.label.parentSuite:⟨VALUE⟩
  • @allure.label.suite:⟨VALUE⟩
  • @allure.label.subSuite:⟨VALUE⟩

Assign the name of suite, as part of Allure's suite-based hierarchy.

JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); await allure.parentSuite("Tests for web interface"); await allure.suite("Tests for essential features"); await allure.subSuite("Tests for authentication"); // ... });
JavaScript
Feature("Test My Website"); Scenario("Test Authentication", async () => { // ... }) .tag("@allure.label.parentSuite:TestsForWebInterface") .tag("@allure.label.suite:TestsForEssentialFeatures") .tag("@allure.label.subSuite:TestsForAuthentication");

Parametrized tests

  • allure.parameter(name: string, value: any, options?: ParameterOptions): Promise<void>

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. This argument is only used by Allure TestOps.

  • 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 the allure_results directory if you publish it.
JavaScript
Feature("Test My Website"); let accounts = new DataTable(["login", "password"]); accounts.add(["johndoe", "qwerty"]); accounts.add(["admin", "qwerty"]); Data(accounts).Scenario("Test Authentication", async ({ current }) => { const allure = codeceptjs.container.plugins("allure"); await allure.parameter("Login", current.login); await allure.parameter("Password", current.password); // ... });

Attachments

  • allure.addAttachment(name: string, buffer: Buffer | string, type: string): Promise<void>

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.

JavaScript
const fs = require("fs"); Feature("Test My Website"); Scenario("Test Authentication", async () => { const allure = codeceptjs.container.plugins("allure"); // ... await allure.addAttachment("Text file", "This is the file content.", "text/plain"); await allure.addAttachment("Screenshot", fs.readFileSync("/path/to/image.png"), "image/png"); });
Powered by
logo

Join our newsletter

Join our community

We aim to make Allure Report as reliable and user-friendly as possible, and together with the community, we're here to help when problems arise.

© 2024 Qameta Software Inc. All rights reserved.