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 theReporter 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
onBegin
onBegin
Called once before running tests. Receives the full configuration and root suite.
onTestBegin
onTestBegin
Called for each test when it starts running.
onStdOut
onStdOut
Called when a test writes to stdout.
onStdErr
onStdErr
Called when a test writes to stderr.
onTestEnd
onTestEnd
Called after each test finishes.
onEnd
onEnd
Called after all tests complete.
onError
onError
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.
Related Resources
Built-in Reporters
Learn about Playwright’s built-in reporters
CI/CD Integration
Configure reporters for continuous integration
