Optimizing Test Reports: Allure Integration in Playwright

Cerosh Jacob
3 min readSep 13, 2023

--

Photo by Lukas Blazek on Unsplash

In the olden days of test automation, test reporting was often done manually. This could be a time-consuming and error-prone process. Allure reporting automates the test reporting process, making it more efficient and accurate.

Playwright has built-in reporting, but Allure reporting offers more features like screenshots, logs, and graphs, which can help troubleshoot failed tests. Allure reporting can also be customized to meet the team's or project’s specific needs. Playwright integrates seamlessly with Allure reporting.

The libraries required for integrating Playwright with Allure reporting are allure-playwright and allure-commandline, both of which can be conveniently installed using the npm command. These libraries enable seamless integration between Playwright test scripts and Allure.

npm i -D @playwright/test allure-playwright
npm install -g allure-commandline --save-dev

The Library allure-playwright serves as a bridge for seamless integration between the Allure reporting framework and the Playwright Test framework. It is specifically designed to work with Playwright.

On the other hand, allure-commandline is a standalone tool. By executing various Allure commands, users can create interactive and informative reports that provide valuable insights into the test suite's performance and results.

zsh: command not found: allure

Error message: ‘zsh: command not found: allure' while integrating Allure with Playwright indicates that the 'allure' command cannot be located in the current environment. This may happen if the Allure Commandline tool is not installed or not properly configured in the system. Correctly installing the Allure Commandline tool is crucial to fix this issue.

After installing the Allure Commandline tool, the user should proceed to confirm its installation status and version to guarantee its successful setup. A simple validation step involves running the following command in the terminal:

allure --version

Running this command will show the Allure Commandline tool version if it’s properly installed and accessible in the environment. This is important to confirm so users can use Allure’s reporting features for testing and automation tasks.

After completing the installation of the allure-playwright library, there are several options to seamlessly integrate it into your Playwright testing workflow.

Integrate via playwright.config.ts: Within playwright.config.ts the file, this can be directly added to the allure-playwright library to your configuration. This allows you to set up Allure integration at the framework level, ensuring that all tests within your project will automatically capture and report relevant data.

Configure via a Config File: Alternatively, the user can configure allure-playwright by creating a custom configuration file. This provides flexibility, as the user can specify detailed settings for Allure reporting independently of the Playwright configuration. By pointing to this configuration file during test execution.

Set Up via Command Line: People who prefer a more dynamic approach can pass the necessary configuration values allure-playwright directly via the command line when running the tests. This method allows users to override configuration settings on the fly, making it suitable for situations where you need to tailor reporting for specific test runs.

npx playwright test first.spec.ts  --headed  --reporter=allure-playwright

This command is used to run Playwright tests with specific configurations, and it collects and formats test execution data using the “allure-playwright” reporter.

allure generate ./allure-results --clean

Allure Commandline searches for XML files created after completing the test execution in the specified directory. These files contain data about test runs, including test cases, steps, descriptions, and more. After processing this data, Allure Commandline generates HTML report files in the specified output directory. The “ — clean” flag first deletes any existing HTML report files in the output directory. Once the command completes, can open the generated Allure report in a web browser.

allure open ./allure-report

Allure Commandline starts a web server on the local machine and opens the default web browser, which navigates to the address where the locally served Allure report is available. Users can navigate through the report to view details about test cases, test steps, descriptions, attachments, and any other information included in the test annotations.

My recent publication compiled a comprehensive collection of 100 similar typescript programs. Each program not only elucidates essential Typescript concepts and expounds upon the significance of test automation but also provides practical guidance on its implementation using Playwright. This resource will undoubtedly be valuable if you look deeper into similar topics.

--

--

No responses yet