Skip to content

Reporter ​

Added in: v1.10

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.

js
// @ts-check

/** @implements {import('@playwright/test/reporter').Reporter} */
class MyReporter {
  constructor(options) {
    console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
  }

  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;
js
import type {
  Reporter, FullConfig, Suite, TestCase, TestResult, FullResult
} from '@playwright/test/reporter';

class MyReporter implements Reporter {
  constructor(options: { customOption?: string } = {}) {
    console.log(`my-awesome-reporter setup with customOption set to ${options.customOption}`);
  }

  onBegin(config: FullConfig, suite: Suite) {
    console.log(`Starting the run with ${suite.allTests().length} tests`);
  }

  onTestBegin(test: TestCase) {
    console.log(`Starting test ${test.title}`);
  }

  onTestEnd(test: TestCase, result: TestResult) {
    console.log(`Finished test ${test.title}: ${result.status}`);
  }

  onEnd(result: FullResult) {
    console.log(`Finished the run: ${result.status}`);
  }
}
export default MyReporter;

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

js
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [['./my-awesome-reporter.ts', { customOption: 'some value' }]],
});

Here is a typical order of reporter calls:

Additionally, reporter.onStdOut() and reporter.onStdErr() are called when standard output is produced in the worker process, possibly during a test execution, and reporter.onError() is called when something went wrong outside of the test execution.

If your custom reporter does not print anything to the terminal, implement reporter.printsToStdio() and return false. This way, Playwright will use one of the standard terminal reporters in addition to your custom reporter to enhance user experience.

Reporter errors

Playwright will swallow any errors thrown in your custom reporter methods. If you need to detect or fail on reporter errors, you must wrap and handle them yourself.

Merged report API notes

When merging multiple blob reports via merge-reports CLI command, the same Reporter API is called to produce final reports and all existing reporters should work without any changes. There some subtle differences though which might affect some custom reporters.

  • Projects from different shards are always kept as separate TestProject objects. E.g. if project 'Desktop Chrome' was sharded across 5 machines then there will be 5 instances of projects with the same name in the config passed to reporter.onBegin().

Methods ​

reporter.onBegin() ​

Added in: v1.10

Called once before running tests. All tests have been already discovered and put into a hierarchy of Suites.

Arguments

  • config FullConfig

    Resolved configuration.

  • suite Suite

    The root suite that contains all projects, files and test cases.

reporter.onEnd() ​

Added in: v1.10 async

Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise] and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the test runner.

Arguments

  • result Object

    Result of the full test run, status can be one of:

    • 'passed' - Everything went as expected.
    • 'failed' - Any test has failed.
    • 'timedout' - The testConfig.globalTimeout has been reached.
    • 'interrupted' - Interrupted by the user.
    • status "passed" | "failed" | "timedout" | "interrupted"

      Test run status.

    • startTime Date

      Test run start wall time.

    • duration int

      Test run duration in milliseconds.

Returns

  • Promise<Object>

reporter.onError() ​

Added in: v1.10

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

Arguments

  • error TestError

    The error.

  • workerInfo WorkerInfo (optional) Added in: v1.60

    Contains information about the worker that produced this error. undefined for errors that are not associated with a specific worker.

reporter.onExit() ​

Added in: v1.33 async

Called immediately before test runner exists. At this point all the reporters have received the reporter.onEnd() signal, so all the reports should be build. You can run the code that uploads the reports in this hook.

reporter.onStdErr() ​

Added in: v1.10

Called when something has been written to the standard error in the worker process.

Arguments

  • 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.

reporter.onStdOut() ​

Added in: v1.10

Called when something has been written to the standard output in the worker process.

Arguments

  • 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.

reporter.onStepBegin() ​

Added in: v1.10

Called when a test step started in the worker process.

Arguments

  • 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.

reporter.onStepEnd() ​

Added in: v1.10

Called when a test step finished in the worker process.

Arguments

  • test TestCase

    Test that the step belongs to.

  • result TestResult

    Result of the test run.

  • step TestStep

    Test step instance that has finished.

reporter.onTestBegin() ​

Added in: v1.10

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

Arguments

  • test TestCase

    Test that has been started.

  • result TestResult

    Result of the test run, this object gets populated while the test runs.

reporter.onTestEnd() ​

Added in: v1.10

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

Arguments

  • test TestCase

    Test that has been finished.

  • result TestResult

    Result of the test run.

reporter.preprocess() ​

Added in: v1.62 async

Called after the configuration has been resolved and before reporter.onBegin(). Allows a reporter to mark individual tests as skipped, excluded, fixed or failing.

Arguments

  • params Object

    The suite reflects --project, --grep/--grep-invert and .only filtering, so it only contains tests that match the current invocation. Setup and dependency projects are readonly and cannot be changed through TestRun.

    The suite ignores the --shard argument: it always contains the full, un-sharded corpus. Playwright applies its built-in sharding after reporter.preprocess() returns, unless the reporter calls testRun.skipSharding().

    • config FullConfig

      Resolved configuration.

    • suite Suite

      The root suite that contains the projects, files and test cases that will run.

    • testRun TestRun

      Control which tests will run and their expected status.

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. If your reporter does not print to the terminal, it is strongly recommended to return false.

Returns

  • boolean

Released under the Apache 2.0 License.