Skip to main content

Overview

Playwright provides a flexible reporter API that allows you to create custom test reporters. Custom reporters enable you to integrate test results with your CI/CD pipeline, send notifications, generate custom reports, or integrate with third-party services.

Reporter API

Custom reporters implement the Reporter interface with lifecycle hooks that are called during test execution.

Core Reporter Methods

Lifecycle Hooks

The reporter lifecycle provides hooks at different stages of test execution.

Available Hooks

Called once before running tests. Receives the full configuration and root suite.
Called for each test when it starts running.
Called when a test writes to stdout.
Called when a test writes to stderr.
Called after each test finishes.
Called after all tests complete.
Called on global errors not associated with a specific test.

Practical Examples

JSON Reporter

Create a custom JSON reporter that outputs structured test results.
JSON Reporter Example

Slack Notification Reporter

Send test results to Slack when tests fail.
Slack Reporter

Custom HTML Reporter

Generate a custom HTML report with test results.
HTML Reporter

Configuration

Register your custom reporter in the Playwright configuration file.
playwright.config.ts

Multiple Reporters

You can use multiple reporters simultaneously. Playwright will call the hooks on all reporters in the order they are defined.

Best Practices

Performance

Keep reporter logic lightweight to avoid slowing down test execution. Use async operations for I/O.

Error Handling

Always handle errors in reporters gracefully. A failing reporter shouldn’t break the test run.

Configuration

Make reporters configurable through constructor options for maximum flexibility.

Standards

Follow common reporting standards (JUnit XML, TAP) when integrating with CI/CD systems.

Built-in Reporters

Learn about Playwright’s built-in reporters

CI/CD Integration

Configure reporters for continuous integration