Skip to main content

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.ts
import { 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.ts
import type { 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)

Added in: v1.10
  • 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)

Added in: v1.10
  • result <Object> Result of the full test run.#

    • status <"passed"|"failed"|"timedout"|"interrupted">

    * `'passed'` - Everything went as expected. * `'failed'` - Any test has failed. * `'timedout'` - The [testConfig.globalTimeout](/playwright/docs/api/class-testconfig#test-config-global-timeout) has been reached. * `'interrupted'` - Interrupted by the user.
  • 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)

Added in: v1.10

Called on some global error, for example unhandled exception in the worker process.

reporter.onStdErr(chunk, test, result)

Added in: v1.10
  • chunk <string|Buffer> Output chunk.#
  • test <void|TestCase> Test that was running. Note that output may happen when no 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)

Added in: v1.10
  • chunk <string|Buffer> Output chunk.#
  • test <void|TestCase> Test that was running. Note that output may happen when no 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)

Added in: v1.10
  • test <TestCase> Test that the step belongs to.#
  • result <TestResult> Result of the test run, this object gets populated while the test runs.#
  • step <TestStep> Test step instance that has started.#
  • returns: <void>#

Called when a test step started in the worker process.

reporter.onStepEnd(test, result, step)

Added in: v1.10

Called when a test step finished in the worker process.

reporter.onTestBegin(test, result)

Added in: v1.10
  • 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)

Added in: v1.10

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

reporter.printsToStdio()

Added in: v1.10

Whether this reporter uses stdio for reporting. When it does not, Playwright Test could add some output to enhance user experience.