Allure CodeceptJS

Allure CodeceptJS npm latest version

Generate beautiful HTML reports using Allure Report and your CodeceptJS tests.

Allure Report CodeceptJS Example

How to start

1. Prepare your project

  1. Open a terminal and go to the project directory. For example:

    Bash
    cd /home/user/myproject
  2. Install the Allure Report command-line tool, if it is not yet installed in your operating system. Note that Allure Report requires Java, see Installation.

    Bash
    npm install --save-dev allure-commandline
    Bash
    yarn add --dev allure-commandline
    Bash
    pnpm install --dev allure-commandline
  3. Install the Allure CodeceptJS adapter.

    Bash
    npm install --save-dev allure-codeceptjs
    Bash
    yarn add --dev allure-codeceptjs
    Bash
    pnpm install --dev allure-codeceptjs
  4. In your codecept.conf.js file, enable the allure plugin.

    JavaScript
    exports.config = { tests: "tests/**.test.js", plugins: { allure: { enabled: true, require: "allure-codeceptjs", }, }, };

2. Run tests

Run your CodeceptJS tests same way as your would run them usually.

For example:

Bash
npx codeceptjs run
Bash
yarn dlx codeceptjs run
Bash
pnpx codeceptjs run

This will save necessary data into allure-results or other directory, according to the configuration. If the directory already exists, the new files will be added to the existing ones, so that a future report will be based on them all.

3. Generate a report

Finally, run Allure to convert the test results into an HTML report. This will automatically open your browser to view the report.

Bash
npx allure serve allure-results
Bash
yarn dlx allure serve allure-results
Bash
pnpx allure serve allure-results

If necessary, replace allure-results with the path to the directory specified in the configuration.

There are some options that can affect how the report is generated, see Allure command-line options.

Writing tests

The Allure CodeceptJS adapter extends the standard reporting features of CodeceptJS by providing additional capabilities for crafting more informative and structured tests. This section highlights key enhancements that can be utilized:

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.

Adding Metadata

Allure allows you to enrich your reports with a variety of metadata. This additional information provides context and details for each test, enhancing the report's usefulness. Refer to the metadata reference section for an exhaustive list of what can be added.

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

Organize tests

As described in Improving navigation in your test report, Allure supports multiple ways to organize tests into hierarchical structures.

To specify a test's location in the 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");

To specify a test's location in the 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");

Divide a test into steps

Test plan is currently not supported by the Allure CodeceptJS adapter.

Describe parametrized tests

If you use the parametrized tests pattern, call the allure.parameter() function to add the parameters to the test report, see the reference.

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); // ... });

Attach screenshots and other files

In Allure reports, you have the ability to attach various types of files, which can greatly enhance the comprehensibility of the report. A common practice is to attach screenshots that capture the state of the user interface at specific moments during test execution.

For detailed instructions on how to implement attachments, refer to the attachments section in the Allure CodeceptJS reference.

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"); });

Select tests via a test plan file

Test plan is currently not supported by the Allure CodeceptJS adapter.

Environment information

For the main page of the report, you can collect various information about the environment in which the tests were executed.

For example, it is a good idea to use this to remember the OS version and Node.js version. This may help the future reader investigate bugs that are reproducible only in some environments.

Allure Report Environments Widget

To provide environment information, put a file named environment.properties into the allure-results directory after running the tests. See the example in Environment file.

Note that this feature should be used for properties that do not change for all tests in the report. If you have properties that can be different for different tests, consider using Parametrized tests.

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.