Reporter
Test runner notifies the reporter about various events during test execution. All methods of the reporter are optional.
You can create a custom reporter by implementing a class with some of the reporter methods. Make sure to export this class as default.
- TypeScript
- JavaScript
// my-awesome-reporter.tsimport { Reporter } from '@playwright/test/reporter';
class MyReporter implements Reporter { onBegin(config, suite) { console.log(`Starting the run with ${suite.allTests().length} tests`); }
onTestBegin(test) { console.log(`Starting test ${test.title}`); }
onTestEnd(test, result) { console.log(`Finished test ${test.title}: ${result.status}`); }
onEnd(result) { console.log(`Finished the run: ${result.status}`); }}export default MyReporter;
// my-awesome-reporter.js// @ts-check
/** @implements {import('@playwright/test/reporter').Reporter} */class MyReporter { onBegin(config, suite) { console.log(`Starting the run with ${suite.allTests().length} tests`); }
onTestBegin(test) { console.log(`Starting test ${test.title}`); }
onTestEnd(test, result) { console.log(`Finished test ${test.title}: ${result.status}`); }
onEnd(result) { console.log(`Finished the run: ${result.status}`); }}
module.exports = MyReporter;
Now use this reporter with testConfig.reporter. Learn more about using reporters.
- TypeScript
- JavaScript
// playwright.config.tsimport { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = { reporter: './my-awesome-reporter.ts',};export default config;
// playwright.config.js// @ts-check
/** @type {import('@playwright/test').PlaywrightTestConfig} */const config = { reporter: './my-awesome-reporter.js',};
module.exports = config;
Here is a typical order of reporter calls:
- reporter.onBegin(config, suite) is called once with a root suite that contains all other suites and tests. Learn more about suites hierarchy.
- reporter.onTestBegin(test, result) is called for each test run. It is given a TestCase that is executed, and a TestResult that is almost empty. Test result will be populated while the test runs (for example, with steps and stdio) and will get final
status
once the test finishes. - reporter.onStepBegin(test, result, step) and reporter.onStepEnd(test, result, step) are called for each executed step inside the test. When steps are executed, test run has not finished yet.
- reporter.onTestEnd(test, result) is called when test run has finished. By this time, TestResult is complete and you can use testResult.status, testResult.error and more.
- reporter.onEnd(result) is called once after all tests that should run had finished.
Additionally, reporter.onStdOut(chunk, test, result) and reporter.onStdErr(chunk, test, result) are called when standard output is produced in the worker process, possibly during a test execution, and reporter.onError(error) is called when something went wrong outside of the test execution.
- reporter.onBegin(config, suite)
- reporter.onEnd(result)
- reporter.onError(error)
- reporter.onStdErr(chunk, test, result)
- reporter.onStdOut(chunk, test, result)
- reporter.onStepBegin(test, result, step)
- reporter.onStepEnd(test, result, step)
- reporter.onTestBegin(test, result)
- reporter.onTestEnd(test, result)
#
reporter.onBegin(config, suite)config
<TestConfig> Resolved configuration.#suite
<Suite> The root suite that contains all projects, files and test cases.#- returns:void># <
Called once before running tests. All tests have been already discovered and put into a hierarchy of Suites.
#
reporter.onEnd(result)result
<Object> Result of the full test run.#status
<"passed"|"failed"|"timedout"|"interrupted">
- returns:Promise<void>># <
Called after all tests has been run, or testing has been interrupted. Note that this method may return a Promise and Playwright Test will await it.
#
reporter.onError(error)Called on some global error, for example unhandled exception in the worker process.
#
reporter.onStdErr(chunk, test, result)chunk
<string|Buffer> Output chunk.#test
<void|TestCase> Test that was running. Note that output may happen when to test is running, in which case this will be void.#result
<void|TestResult> Result of the test run, this object gets populated while the test runs.#- returns:void># <
Called when something has been written to the standard error in the worker process.
#
reporter.onStdOut(chunk, test, result)chunk
<string|Buffer> Output chunk.#test
<void|TestCase> Test that was running. Note that output may happen when to test is running, in which case this will be void.#result
<void|TestResult> Result of the test run, this object gets populated while the test runs.#- returns:void># <
Called when something has been written to the standard output in the worker process.
#
reporter.onStepBegin(test, result, step)test
<TestCase> Test that has been started.#result
<TestResult> Result of the test run, this object gets populated while the test runs.#step
<TestStep> Test step instance.#- returns:void># <
Called when a test step started in the worker process.
#
reporter.onStepEnd(test, result, step)test
<TestCase> Test that has been finished.#result
<TestResult> Result of the test run.#step
<TestStep> Test step instance.#- returns:void># <
Called when a test step finished in the worker process.
#
reporter.onTestBegin(test, result)test
<TestCase> Test that has been started.#result
<TestResult> Result of the test run, this object gets populated while the test runs.#- returns:void># <
Called after a test has been started in the worker process.
#
reporter.onTestEnd(test, result)test
<TestCase> Test that has been finished.#result
<TestResult> Result of the test run.#- returns:void># <
Called after a test has been finished in the worker process.