Skip to main content
Version: 1.15

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.

// 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;

Now use this reporter with testConfig.reporter. Learn more about using reporters.

// playwright.config.tsimport { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {  reporter: './my-awesome-reporter.ts',};export default config;

Here is a typical order of reporter calls:

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)#

  • 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)#

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)#

Called after a test has been finished in the worker process.