new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · Test runner API · all subjects

reporter

16 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Reporter class basic structure

The Reporter class is the base for custom reporters in Playwright Test. All methods of the Reporter class are optional. A custom reporter is created by implementing a class with some of the reporter methods and exporting it as default.

Reporter onBegin method

onBegin(config: FullConfig, suite: Suite) is called once before running tests. All tests have been already discovered and put into a hierarchy of Suites. The config parameter contains the resolved configuration. The suite parameter is the root suite that contains all projects, files and test cases.

Reporter onEnd method

onEnd(result: Object) is called after all tests have been run, or testing has been interrupted. The result object contains status (one of 'passed', 'failed', 'timedout', 'interrupted'), startTime as a Date, and duration in milliseconds. This method may return a Promise and Playwright Test will await it. The reporter is allowed to override the status and hence affect the exit code of the test runner.

Reporter onStepBegin method

onStepBegin(test: TestCase, result: TestResult, step: TestStep) is called when a test step started in the worker process. The test parameter is the TestCase that the step belongs to. The result parameter is the TestResult that is being populated while the test runs. The step parameter is the TestStep instance that has started.

Reporter onStepEnd method

onStepEnd(test: TestCase, result: TestResult, step: TestStep) is called when a test step finished in the worker process. The test parameter is the TestCase that the step belongs to. The result parameter is the complete TestResult. The step parameter is the TestStep instance that has finished.

Reporter onStdErr method

onStdErr(chunk: string | Buffer, test?: TestCase, result?: TestResult) is called when something has been written to the standard error in the worker process. The chunk parameter is the output chunk. The test parameter is the TestCase that was running, or void if no test is running. The result parameter is the TestResult that gets populated while the test runs, or void.

Reporter onError method

onError(error: TestError, workerInfo?: WorkerInfo) is called on some global error, for example unhandled exception in the worker process. The error parameter is the TestError. The workerInfo parameter is optional and contains information about the worker that produced this error, or undefined for errors not associated with a specific worker.

Reporter onExit method

onExit() is called immediately before the test runner exits. At this point all the reporters have received the onEnd signal, so all the reports should be built. This method may return a Promise. You can run code that uploads reports in this hook.

Reporter printsToStdio method

printsToStdio() returns a boolean indicating whether this reporter uses stdio for reporting. When it returns false, 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.

Reporter preprocess method

preprocess(params: Object) is called after the configuration has been resolved and before onBegin. It allows a reporter to mark individual tests as skipped, excluded, fixed or failing. The params object contains config (FullConfig), suite (Suite), and testRun (TestRun). This method may return a Promise.

Reporter lifecycle order

The typical order of reporter calls is: onBegin (once with root suite), onTestBegin (for each test run), onStepBegin and onStepEnd (for each step), onTestEnd (when test run finishes), onEnd (once after all tests), onExit (immediately before test runner exits). Additionally, onStdOut and onStdErr are called when output is produced, and onError is called on global errors.

Reporter error handling

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

Reporter 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 changes. Projects from different shards are always kept as separate TestProject objects. If project 'Desktop Chrome' was sharded across 5 machines, there will be 5 instances of projects with the same name in the config passed to onBegin.

Custom reporter example

// @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; This example shows a basic custom reporter implementation in JavaScript with constructor, onBegin, onTestBegin, onTestEnd, and onEnd methods.

Using custom reporter in config

Custom reporters are used in the playwright.config.ts file through the reporter configuration property. The reporter property takes an array of reporter definitions, each containing the path to the reporter file and optionally an options object. Example: reporter: [['./my-awesome-reporter.ts', { customOption: 'some value' }]]

Reporter onEnd result status values

The status in the onEnd result object can be one of: 'passed' (everything went as expected), 'failed' (any test has failed), 'timedout' (the TestConfig.globalTimeout has been reached), or 'interrupted' (interrupted by the user).

Give your agent this brain