Allure WebdriverIO reference

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

Metadata

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

Description

  • addDescription(name: string, descriptionType: string)

Set the test's description.

The second argument determines how the text will be rendered. If it is equal to TYPE.MARKDOWN, the text will be interpreted using the Markdown syntax. Any HTML formatting, if present, will be stripped for security purposes. To keep the HTML intact, pass TYPE.HTML to the second argument.

Using HTML descriptions is unsafe and can potentially break the test report's layout or even create an XSS attack vector for your organization.

TypeScript
import { addDescription, TYPE } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addDescription("Attempt to log into the website.", TYPE.MARKDOWN); // ... });

Owner

  • addOwner(owner: string)

Set the test's owner.

TypeScript
import { addOwner } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addOwner("John Doe"); // ... });

Tag

  • addTag(tag: string)

Set the test's tags.

TypeScript
import { addTag } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addTag("web interface"); addTag("authentication"); // ... });

Severity

  • addSeverity(severity: string)

Set the test's severity.

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

TypeScript
import { addSeverity } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addSeverity("critical"); // ... });

Label

  • addLabel(name: string, value: string)

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 addLabel() multiple times to create an array of values under the given name.

TypeScript
import { addLabel } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addLabel("my custom label", "value"); // ... });

ID

  • addAllureId(allureId: string)

Set the test's ID.

TypeScript
import { addAllureId } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addAllureId("123"); // ... });
  • addLink(url: string, name?: string, type?: string)
  • addIssue(issue: string)
  • addTestId(testId: string)

Add a link related to the test.

Based on the type (which can be any string), Allure will try to load a corresponding link pattern to process the URL, as defined by the issueLinkTemplate and tmsLinkTemplate configuration options. If no pattern found for the given type, the link will not be added.

The name will be used as the link's text. If it is omitted, the URL will be used instead.

For convenience, Allure provides two shorthand functions with pre-selected link types: addIssue() and addTestId().

TypeScript
import { addIssue, addLink, addTestId } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addLink("https://dev.example.com/", "Website"); addIssue("AUTH-123"); addTestId("TMS-456"); // ... });

If you use the Cucumber.js runner and you have the useCucumberStepReporter option enabled, you can also add links via the @issue and @testId Gherkin tags.

Gherkin
Feature: Labels @issue=AUTH-123 @testId=TMS-456 Scenario: Create new label for authorized user When I open labels page And I create label with title "hello" Then I should see label with title "hello"

Behavior-based hierarchy

  • addEpic(epicName: string)
  • addFeature(featureName: string)
  • addStory(storyName: string)

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

TypeScript
import { addEpic, addFeature, addStory } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addEpic("Web interface"); addFeature("Essential features"); addStory("Authentication"); // ... });

If you are using the Cucumber.js runner, Allure WebdriverIO uses the hierarchy from the Gherkin files by default. The exact behavior depends on the useCucumberStepReporter option.

Suite-based hierarchy

  • addParentSuite(suiteName: string)
  • addSuite(suiteName: string)
  • addSubSuite(suiteName: string)

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

TypeScript
import { addParentSuite, addSubSuite, addSuite } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { addParentSuite("Tests for web interface"); addSuite("Tests for essential features"); addSubSuite("Tests for authentication"); // ... });

If you are using the Cucumber.js runner, Allure WebdriverIO uses the hierarchy from the Gherkin files by default. The exact behavior depends on the useCucumberStepReporter option.

Test steps

  • step(name: string, body: StepBodyFunction): Promise<void>
  • addStep(title: string, { content, name, type }?: any, status?: Status)
  • startStep(title: string)
  • endStep(status?: Status)

Define test steps.

There are three ways of defining a step.

  • Lambda steps

    Write a test step in an asynchronous lambda function and pass it to allureReporter.step(). The lambda function must accept either no arguments or a single argument of the AllureCommandStepExecutable type. You can create sub-steps within the current step by calling this argument's step() method.

  • No-op steps

    If you call allureReporter.addStep(), Allure will add to the report a no-op step. This allows for a log-style reporting within a test or within a larger step. A no-op step finishes immediately after it started and cannot have any sub-steps, or parameters.

    The optional second argument indicates the status that will be shown for the step in the report. Allowed values are: Status.PASSED (the default), Status.FAILED, Status.BROKEN, and Status.SKIPPED.

  • Low-level steps

    Call allureReporter.startStep() and allureReporter.endStep() to manually indicate to Allure WebdriverIO when a step starts or ends. It is recommended to use try..catch blocks to ensure ending the steps regardless of the exceptions thrown during their execution, see the example below.

    The optional argument for endStep() indicates the status that will be shown for the step in the report. Allowed values are: Status.PASSED (the default), Status.FAILED, Status.BROKEN, and Status.SKIPPED.

TypeScript
import { step } from "@wdio/allure-reporter"; it("Test Authentication"), async () => { await step("Step 1", async (step) => { await step.step("Step 1.1", async () => { // ... }); await step.step("Step 1.2", async () => { // ... }); }); await step("Step 2", async (step) => { await step.step("Step 2.1", async () => { // ... }); await step.step("Step 2.2", async () => { // ... }); }); });
TypeScript
import { addStep } from "@wdio/allure-reporter"; import { Status } from "allure-js-commons"; it("Test Authentication"), async () => { addStep("Successful step"); addStep("Skipped step", undefined, Status.SKIPPED); addStep( "Skipped step with attachment", { content: "This is attachment.", name: "file.txt", type: "text/plain" }, Status.SKIPPED, ); });
TypeScript
import { endStep, startStep } from "@wdio/allure-reporter"; import { Status } from "allure-js-commons"; it("Test Authentication"), async () => { startStep("Step 1"); try { // ... endStep(); } catch { endStep(Status.FAILED); } startStep("Step 2"); try { // ... endStep(); } catch { endStep(Status.FAILED); } });

By default, Allure WebdriverIO automatically adds a step for each WebDriver command, with both request details and response data added as step-level attachments. This can be disabled, see disableWebdriverStepsReporting.

Parametrized tests

  • allureReporter.addArgument(name: string, value: string)

Since tests in WebdriverIO, unlike in some other frameworks, are written as anonymous functions, it is very easy to implement the parametrized tests pattern, i.e. to run the same test logic with different test data. To do so, just write the test inside a loop and use the variable parameters in both its title and its body.

To display a parameter value in the test report, pass it to the addArgument() function.

TypeScript
import { addArgument } from "@wdio/allure-reporter"; for (const login of ["johndoe", "[email protected]"]) { it(`Test Authentication as ${login}`, async () => { addArgument("login", login); // ... }); }

Attachments

  • addAttachment(name: string, content: string | Buffer | object, type: string)

Add content as an attachment to the test result. The content can be a text string or a base64-encoded Buffer. As the type argument, pass the MIME type of content.

You can use data produced by any function, not necessarily read from an actual file.

TypeScript
import { addAttachment } from "@wdio/allure-reporter"; import * as fs from "fs"; it("Test Authentication"), async () => { // ... addAttachment("Text", "This is the file content.", "text/plain"); addAttachment("Screenshot", fs.readFileSync("/path/to/image.png"), "image/png"); });

By default, Allure WebdriverIO automatically includes in the report all screenshots taken via the WebdriverIO's saveScreenshot() function. This can be disabled, see the disableWebdriverScreenshotsReporting configuration option.

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.