Integrations

ReportPortal integration with Playwright

arrow leftBack to blog
userReportPortal Team
calendarJune 6, 2024

If the Playwright used on your project to write and run tests, the results can reach the ReportPortal via the agent-js-playwright. The agent is a custom Playwright reporter that sends test execution results to ReportPortal.

Let's walk through the steps to set up integration.

You can also watch our video guide about ReportPortal integration with Playwright.

Installing the Agent

The first step involves installing the agent into the project. There is a small project with a few Playwright tests.

Small project with a few Playwright tests

The tests are simple.

Simple tests

The agent package is available on NPM and GitHub registries.

Below, you can find the commands to install it using npm, yarn or pnpm.

Commands to install using npm, yarn or pnpm

After installation, it will appear in the list of dependencies. At the time of writing this article, the latest version is 5.1.8.

After the installation, it is required to provide some ReportPortal configuration data.

Configuration of the Agent

The next step involves configuring the agent and providing some basic options that will connect ReportPortal with the project.

First, create a Playwright config file if you don't have one.

The basic configuration is presented below.

Playwright config file

The ‘dotenv/config’ used to get access to the ENVIRONMENT variables specified in ‘.env’ file.  It will be used to store the API key value.

To obtain the configuration options, the ReportPortal profile page can be used.

1. Open the ReportPortal instance (if you don’t have one the demonstration instance can be used) and log in. For a demo instance the GitHub login can be used.

Demonstration instance of our test reporting tool

2. Then navigate to the profile page. There, we can find a configuration example for Node.js.

Profile page in our test automation reporting dashboard
Configuration example for Node.js

3. Simply copy the JSON object and paste it into your project file assigning it to a variable, f.e. ‘rpConfig’.

Let’s name the launch as f.e. ‘Custоm regressiоn with Playwright’ right after that.

rpConfig

4. Provide an API key which can be generated on the API keys page in your profile.

Open the API Keys page and click on ‘Generate API Key’ button.

Generate API Key

Specify the API Key name and click on ‘Generate’.

API Key name

Detailed API Keys description can be found in the documentation.

After generation the API Key can be copied to use it in the code.

Paste it as a value for REPORTPORTAL_API_KEY in ‘.env’ file and update ‘rpConfig’.

REPORTPORTAL_API_KEY

5. Instruct Playwright to use the agent as a reporter.

Instructing Playwright to use the agent as a reporter

NOTE:

The full list of options with their description can be found in the agent’s repository.

Running the Tests

After completing the two steps above, run tests as usual.

1. Run "npm run test" command.

Running "npm run test" command

2. Monitor the test's progress in ReportPortal. The state can be refreshed to obtain the latest results.

Monitoring the test's progress in ReportPortal

Let’s check the embedded reporter of Playwright. The statistics here match exactly.

 The embedded reporter of Playwright

Update tests with additional data

You can enrich your Playwright test report by adding additional data. This includes description, attributes, logs, attachments, TestCaseID and status.

Description and attributes can be used to specify any extra information about the test and can also be used for filtering and building some widgets, like "Component Health Check". Extra logs can also be provided together with attachments. The TestCaseID can be used as a history ID across different launches. There's also the option to change the status in ReportPortal for a particular test result.

How to add additional data to the tests?

1. To provide attributes and a description, import the "ReportingApi" from the agent package and use it within tests.

Importing the "ReportingApi" from the agent package
Providing attributes and description

After running the tests again, the specified data will be visible in ReportPortal in the newly appeared launch. We just need to drill down into it to see the results.

Newly appeared launch in ReportPortal
Playwright tests in ReportPortal

2. To add logs with specific log levels, use the Reporting API methods or report as is if you're writing logs to the standard output.

Adding logs with specific log levels

Let's run our tests again and check the new launch in the system. To see the logs for particular test result, we can drill down to its latest level.

The logs for particular test result

The error logs thrown by the failed tests are reported by default on the test end.

The error logs

3. To insert attachments, call the "attach" method on the "testInfo" object provided by Playwright.

Adding attachments

After launch appearing in ReportPortal, the attachments can be found on the same place as logs.

Providing TestCaseID

4. The TestCaseID is a unique test case identifier across all launches in ReportPortal. It is generated automatically based on code reference (physical location of the test within the project) and parameters (if exists). But the real test case ID from your test case management system can be used instead. To provide TestCaseID explicitly, call the "setTestCaseId" method of " ReportingApi" and provide a value.

Test item details modal window

Applied TestCaseID can be checked via Test item details modal window.

Test item details modal window

NOTE:

Once the TestCaseID changed for the test result, it will be unlinked from its previous executions from historical data perspective.

Historical data perspective

History of this test result within previous launches, where the TestCaseID was persistent between runs.

History of the test

5. In case for some reason necessary to set the specific status for test result in ReportPortal only, the "ReportingApi" "setStatus" methods can be used.

Provide the specific status for test result in ReportPortal

Now in ReportPortal we can check that test that actually failed marked as ‘passed’ in the system.

Test that actually failed marked as ‘passed’ in the system

NOTE:

Detailed information about the additional data and methods for adding it can be found in the agent's repository within the Readme instructions.

By this step-by-step process, you can fully integrate your Playwright automation with ReportPortal. Once set up, you can view test results in real-time, which is particularly useful for lengthy and extensive test suites. Moreover, ReportPortal can analyze your data using Machine Learning algorithms. If you're looking to expedite the process, you can delegate it to the ReportPortal Analyzer to quickly identify the root causes of defects. 

ReportPortal also provides a comprehensive visualization of your automation process, allowing you to generate charts, track test automation metrics, and keep an eye on your project's stability with our test reporting dashboard. 

Bring your Playwright test reporting to the next level! 

Useful links: