2021-05-27 20:30:03 -07:00
---
id: test-reporters
title: "Reporters"
---
2021-07-18 12:07:45 +02:00
Playwright Test comes with a few built-in reporters for different needs and ability to provide custom reporters. The easiest way to try out built-in reporters is to pass `--reporter` [command line option ](./test-cli.md ).
2021-05-27 20:30:03 -07:00
2021-06-02 09:23:06 -07:00
```bash
2021-05-27 20:30:03 -07:00
npx playwright test --reporter=line
```
2021-05-31 20:17:15 -07:00
For more control, you can specify reporters programmatically in the [configuration file ](./test-configuration.md ).
2021-05-27 20:30:03 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-27 20:30:03 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-05-31 20:17:15 -07:00
reporter: 'line',
2023-01-12 13:12:02 -08:00
});
2021-05-31 20:17:15 -07:00
```
2021-07-12 16:51:43 -07:00
### Multiple reporters
2022-09-12 06:11:52 -07:00
You can use multiple reporters at the same time. For example you can use `'list'` for nice terminal output and `'json'` to get a comprehensive json file with the test results.
2021-07-12 16:51:43 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-07-12 16:51:43 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-07-12 16:51:43 -07:00
reporter: [
['list'],
['json', { outputFile: 'test-results.json' }]
],
2023-01-12 13:12:02 -08:00
});
2021-07-12 16:51:43 -07:00
```
### Reporters on CI
2021-10-04 05:50:55 -07:00
You can use different reporters locally and on CI. For example, using concise `'dot'` reporter avoids too much output. This is the default on CI.
2021-05-27 20:30:03 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-27 20:30:03 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-07-12 16:51:43 -07:00
// Concise 'dot' for CI, default 'list' when running locally
reporter: process.env.CI ? 'dot' : 'list',
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
## Built-in reporters
All built-in reporters show detailed information about failures, and mostly differ in verbosity for successful runs.
### List reporter
2021-10-04 05:50:55 -07:00
List reporter is default (except on CI where the `dot` reporter is default). It prints a line for each test being run.
2021-05-31 20:17:15 -07:00
2021-06-02 09:23:06 -07:00
```bash
2021-05-31 20:17:15 -07:00
npx playwright test --reporter=list
```
2021-05-27 20:30:03 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-31 20:17:15 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-05-27 20:30:03 -07:00
reporter: 'list',
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
Here is an example output in the middle of a test run. Failures will be listed at the end.
2021-06-02 09:23:06 -07:00
```bash
2021-05-27 20:30:03 -07:00
npx playwright test --reporter=list
Running 124 tests using 6 workers
2022-10-24 18:54:53 -04:00
1 ✓ should access error in env (438ms)
2 ✓ handle long test names (515ms)
3 x 1) render expected (691ms)
4 ✓ should timeout (932ms)
5 should repeat each:
6 ✓ should respect enclosing .gitignore (569ms)
7 should teardown env after timeout:
8 should respect excluded tests:
9 ✓ should handle env beforeEach error (638ms)
10 should respect enclosing .gitignore:
```
You can opt into the step rendering via passing the following config option:
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2022-10-24 18:54:53 -04:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2022-11-30 15:37:31 -08:00
reporter: [['list', { printSteps: true }]],
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
### Line reporter
2022-07-13 13:54:26 -07:00
Line reporter is more concise than the list reporter. It uses a single line to report last finished test, and prints failures when they occur. Line reporter is useful for large test suites where it shows the progress but does not spam the output by listing all the tests.
2021-05-31 20:17:15 -07:00
2021-06-02 09:23:06 -07:00
```bash
2021-05-31 20:17:15 -07:00
npx playwright test --reporter=line
```
2021-05-27 20:30:03 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-31 20:17:15 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-05-27 20:30:03 -07:00
reporter: 'line',
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
Here is an example output in the middle of a test run. Failures are reported inline.
2021-06-02 09:23:06 -07:00
```bash
2021-05-27 20:30:03 -07:00
npx playwright test --reporter=line
Running 124 tests using 6 workers
1) dot-reporter.spec.ts:20:1 › render expected ===================================================
Error: expect(received).toBe(expected) // Object.is equality
Expected: 1
Received: 0
2022-07-13 13:54:26 -07:00
[23/124] gitignore.spec.ts - should respect nested .gitignore
2021-05-27 20:30:03 -07:00
```
### Dot reporter
2021-10-04 05:50:55 -07:00
Dot reporter is very concise - it only produces a single character per successful test run. It is the default on CI and useful where you don't want a lot of output.
2021-05-31 20:17:15 -07:00
2021-06-02 09:23:06 -07:00
```bash
2021-05-31 20:17:15 -07:00
npx playwright test --reporter=dot
```
2021-05-27 20:30:03 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-31 20:17:15 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-05-27 20:30:03 -07:00
reporter: 'dot',
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
Here is an example output in the middle of a test run. Failures will be listed at the end.
2021-06-02 09:23:06 -07:00
```bash
2021-05-27 20:30:03 -07:00
npx playwright test --reporter=dot
Running 124 tests using 6 workers
······F·············································
```
2021-10-15 07:15:30 -08:00
### HTML reporter
HTML reporter produces a self-contained folder that contains report for the test run that can be served as a web page.
```bash
2021-10-15 18:18:56 -08:00
npx playwright test --reporter=html
2021-10-15 07:15:30 -08:00
```
2021-10-29 15:24:08 -08:00
By default, HTML report is opened automatically if some of the tests failed. You can control this behavior via the
2023-08-17 00:48:59 -07:00
`open` property in the Playwright config or the `PW_TEST_HTML_REPORT_OPEN` environmental variable. The possible values for that property are `always` , `never` and `on-failure`
2021-10-29 15:24:08 -08:00
(default).
2022-09-25 23:36:38 -04:00
You can also configure `host` and `port` that are used to serve the HTML report.
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-10-29 15:24:08 -08:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2022-10-24 18:54:53 -04:00
reporter: [['html', { open: 'never' }]],
2023-01-12 13:12:02 -08:00
});
2021-10-29 15:24:08 -08:00
```
2021-10-15 07:15:30 -08:00
By default, report is written into the `playwright-report` folder in the current working directory. One can override
that location using the `PLAYWRIGHT_HTML_REPORT` environment variable or a reporter configuration.
In configuration file, pass options directly:
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-10-15 07:15:30 -08:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2022-10-24 18:54:53 -04:00
reporter: [['html', { outputFolder: 'my-report' }]],
2023-01-12 13:12:02 -08:00
});
2021-10-15 07:15:30 -08:00
```
2023-04-18 21:25:11 +03:00
If you are uploading attachments from data folder to other location, you can use `attachmentsBaseURL` option to let html report where to look for them.
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-04-18 21:25:11 +03:00
import { defineConfig } from '@playwright/test ';
export default defineConfig({
reporter: [['html', { attachmentsBaseURL: 'https://external-storage.com/' }]],
});
```
2021-10-15 07:15:30 -08:00
A quick way of opening the last test run report is:
```bash
npx playwright show-report
```
Or if there is a custom folder name:
```bash
npx playwright show-report my-report
```
2023-08-18 10:50:59 -07:00
### Blob reporter
2022-07-11 15:34:24 -05:00
2023-08-18 10:50:59 -07:00
Blob reports contain all the details about the test run and can be used later to produce any other report. Their primary function is to facilitate the merging of reports from [sharded tests ](./test-sharding.md ).
```bash
npx playwright test --reporter=blob
```
By default, the report is written into the `blob-report` directory in the package.json directory or current working directory (if no package.json is found). The output directory can be overridden in the configuration file:
```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test ';
export default defineConfig({
reporter: [['blob', { outputDir: 'my-report' }]],
});
```
2021-10-15 07:15:30 -08:00
2021-05-27 20:30:03 -07:00
### JSON reporter
2021-11-03 08:25:16 -07:00
JSON reporter produces an object with all information about the test run.
2021-05-27 20:30:03 -07:00
2021-05-31 20:17:15 -07:00
Most likely you want to write the JSON to a file. When running with `--reporter=json` , use `PLAYWRIGHT_JSON_OUTPUT_NAME` environment variable:
2021-10-04 15:45:52 +02:00
2022-06-10 16:34:31 -08:00
```bash tab=bash-bash
2021-11-03 08:25:16 -07:00
PLAYWRIGHT_JSON_OUTPUT_NAME=results.json npx playwright test --reporter=json
2021-10-04 15:45:52 +02:00
```
2021-08-02 16:21:30 +02:00
2022-06-10 16:34:31 -08:00
```batch tab=bash-batch
2021-08-02 16:21:30 +02:00
set PLAYWRIGHT_JSON_OUTPUT_NAME=results.json
2021-11-03 08:25:16 -07:00
npx playwright test --reporter=json
2021-10-04 15:45:52 +02:00
```
2021-08-02 16:21:30 +02:00
2022-06-10 16:34:31 -08:00
```powershell tab=bash-powershell
2021-08-02 16:21:30 +02:00
$env:PLAYWRIGHT_JSON_OUTPUT_NAME="results.json"
2021-11-03 08:25:16 -07:00
npx playwright test --reporter=json
2021-05-27 20:30:03 -07:00
```
In configuration file, pass options directly:
2021-06-21 19:56:30 +02:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-31 20:17:15 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2022-10-24 18:54:53 -04:00
reporter: [['json', { outputFile: 'results.json' }]],
2023-01-12 13:12:02 -08:00
});
2021-05-27 20:30:03 -07:00
```
### JUnit reporter
2021-11-03 08:25:16 -07:00
JUnit reporter produces a JUnit-style xml report.
2021-05-27 20:30:03 -07:00
2021-05-31 20:17:15 -07:00
Most likely you want to write the report to an xml file. When running with `--reporter=junit` , use `PLAYWRIGHT_JUNIT_OUTPUT_NAME` environment variable:
2021-10-04 15:45:52 +02:00
2022-06-10 16:34:31 -08:00
```bash tab=bash-bash
2021-11-03 08:25:16 -07:00
PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml npx playwright test --reporter=junit
2021-10-04 15:45:52 +02:00
```
2021-08-02 16:21:30 +02:00
2022-06-10 16:34:31 -08:00
```batch tab=bash-batch
2021-08-02 16:21:30 +02:00
set PLAYWRIGHT_JUNIT_OUTPUT_NAME=results.xml
2021-11-03 08:25:16 -07:00
npx playwright test --reporter=junit
2021-10-04 15:45:52 +02:00
```
2021-08-02 16:21:30 +02:00
2022-06-10 16:34:31 -08:00
```powershell tab=bash-powershell
2021-08-02 16:21:30 +02:00
$env:PLAYWRIGHT_JUNIT_OUTPUT_NAME="results.xml"
2021-11-03 08:25:16 -07:00
npx playwright test --reporter=junit
2021-05-27 20:30:03 -07:00
```
In configuration file, pass options directly:
2021-05-31 20:17:15 -07:00
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-05-31 20:17:15 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2022-10-24 18:54:53 -04:00
reporter: [['junit', { outputFile: 'results.xml' }]],
2023-01-12 13:12:02 -08:00
});
2021-05-31 20:17:15 -07:00
```
2021-08-06 14:02:41 -07:00
2021-10-20 07:56:03 -07:00
### GitHub Actions annotations
2021-11-03 08:25:16 -07:00
You can use the built in `github` reporter to get automatic failure annotations when running in GitHub actions.
2021-10-20 07:56:03 -07:00
Note that all other reporters work on GitHub Actions as well, but do not provide annotations.
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-10-20 07:56:03 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-10-20 07:56:03 -07:00
// 'github' for GitHub Actions CI to generate annotations, plus a concise 'dot'
// default 'list' when running locally
2021-11-03 08:25:16 -07:00
reporter: process.env.CI ? 'github' : 'list',
2023-01-12 13:12:02 -08:00
});
2021-10-20 07:56:03 -07:00
```
2021-08-06 14:02:41 -07:00
## Custom reporters
You can create a custom reporter by implementing a class with some of the reporter methods. Learn more about the [Reporter] API.
2023-05-10 23:30:51 +02:00
```js title="my-awesome-reporter.ts"
2023-08-02 11:23:47 +02:00
import type {
FullConfig, FullResult, Reporter, Suite, TestCase, TestResult
} from '@playwright/test/reporter ';
2021-08-06 14:02:41 -07:00
class MyReporter implements Reporter {
2023-01-06 13:39:17 +01:00
onBegin(config: FullConfig, suite: Suite) {
2021-08-06 14:02:41 -07:00
console.log(`Starting the run with ${suite.allTests().length} tests` );
}
2023-01-06 13:39:17 +01:00
onTestBegin(test: TestCase, result: TestResult) {
2021-08-06 14:02:41 -07:00
console.log(`Starting test ${test.title}` );
}
2023-01-06 13:39:17 +01:00
onTestEnd(test: TestCase, result: TestResult) {
2021-08-06 14:02:41 -07:00
console.log(`Finished test ${test.title}: ${result.status}` );
}
2023-01-06 13:39:17 +01:00
onEnd(result: FullResult) {
2021-08-06 14:02:41 -07:00
console.log(`Finished the run: ${result.status}` );
}
}
2023-01-06 13:39:17 +01:00
2021-08-06 14:02:41 -07:00
export default MyReporter;
```
Now use this reporter with [`property: TestConfig.reporter` ].
2023-05-10 18:38:12 +02:00
```js title="playwright.config.ts"
2023-01-12 13:12:02 -08:00
import { defineConfig } from '@playwright/test ';
2021-08-06 14:02:41 -07:00
2023-01-12 13:12:02 -08:00
export default defineConfig({
2021-08-06 14:02:41 -07:00
reporter: './my-awesome-reporter.ts',
2023-01-12 13:12:02 -08:00
});
2021-08-06 14:02:41 -07:00
```
2022-04-27 19:37:59 +01:00
## Third party reporter showcase
2021-08-06 14:02:41 -07:00
2022-04-27 19:37:59 +01:00
* [Allure ](https://www.npmjs.com/package/allure-playwright )
2023-08-14 11:33:44 +02:00
* [Currents ](https://www.npmjs.com/package/@currents/playwright )
2022-08-11 06:13:53 +08:00
* [Monocart ](https://github.com/cenfun/monocart-reporter )
2022-10-04 19:14:41 +09:00
* [ReportPortal ](https://github.com/reportportal/agent-js-playwright )
2023-06-02 23:13:32 +02:00
* [Serenity/JS ](https://serenity-js.org/handbook/test-runners/playwright-test )
2023-08-14 11:33:44 +02:00
* [Testmo ](https://github.com/jonasclaes/playwright-testmo-reporter )
* [Tesults ](https://www.tesults.com/docs/playwright )