Creating a Custom Reporter
Reporter Interface
All methods are optional. Implement only the events you need.onBegin(config, suite)
Called once before running tests. All tests have been discovered and organized into a suite hierarchy.Resolved test configuration
Root suite containing all projects, files, and test cases
onTestBegin(test, result)
Called when a test begins execution.The test that is starting
Test result object (initially empty, populated during execution)
onStdOut(chunk, test, result)
Called when the worker process writes to stdout.Output data
Test that was running (may be undefined if output occurred outside a test)
Test result object (may be undefined)
onStdErr(chunk, test, result)
Called when the worker process writes to stderr.Error output data
Test that was running (may be undefined)
Test result object (may be undefined)
onStepBegin(test, result, step)
Called when a test step begins.The test containing this step
Test result object
The step that is starting
onStepEnd(test, result, step)
Called when a test step completes.The test containing this step
Test result object
The completed step
onTestEnd(test, result)
Called when a test completes. The result object is fully populated at this point.The completed test
Complete test result with status, errors, and timing
onError(error)
Called on global errors that occur outside of test execution.Error object with message and optional stack trace
onEnd(result)
Called after all tests have finished or testing was interrupted. Can return a Promise.Overall test run result
Promise<{ status?: FullResult['status'] }> | void
Reporters can override the final status:
onExit()
Called immediately before the test runner exits. All reporters have receivedonEnd at this point.
printsToStdio()
Indicates whether the reporter outputs to stdout/stderr. Returns:boolean
Return false if your reporter doesn’t print to the terminal. Playwright will use a standard terminal reporter alongside your custom reporter.
Event Order
Typical sequence of reporter calls:onBegin(config, suite)- Called once with the root suite- For each test:
onTestBegin(test, result)- Test startsonStepBegin(test, result, step)- Each step startsonStepEnd(test, result, step)- Each step completesonStdOut(chunk, test, result)- Any stdout outputonStdErr(chunk, test, result)- Any stderr outputonTestEnd(test, result)- Test completes
onError(error)- Any global errorsonEnd(result)- All tests finishedonExit()- Before runner exits
Merged Reports
When using theblob reporter with merge-reports, the same Reporter API is called. Key differences:
- Projects from different shards are kept as separate
TestProjectobjects - If a project was sharded across 5 machines, there will be 5 project instances with the same name
Error Handling
Playwright swallows errors thrown in reporter methods. If you need error detection:Full Result Status
Thestatus field in FullResult can be:
'passed'- All tests passed as expected'failed'- At least one test failed'timedout'- Global timeout reached'interrupted'- User interrupted the run
Related
- Built-in Reporters - Available reporter options
- TestCase - Test case API reference
- TestResult - Test result API reference
