Whether you're running a handful of tests or scaling up to hundreds, knowing what happened, where it failed, and how to debug it fast is crucial. Thatās where Playwright reporters become your best friends.
In this blog, Iāll take you on a tour of Playwrightās built-in reporters, show you sample test scripts, and (yes!) include screenshots of each report in action so you can see the difference.
š§ What Are Reporters?
Reporters are like your test suite's storytellers. After executing your tests, they summarize the resultsāeither in your terminal or in beautiful visual formats. Think of them as:
- Terminal dashboards
- Structured outputs for CI/CD
- Visual tools for debugging
- Data sources for analytics
š§Ŗ Sample Test File
Hereās the test script Iām using for this blog. Each test is designed to showcase one type of reporter:
const { test, expect } = require('@playwright/test');
test('List reporter example (updated)', async ({ page }) => {
await page.goto('https://www.iana.org');
await expect(page).toHaveTitle(/Internet Assigned Numbers Authority/);
});
test('Dot reporter example', async ({ page }) => {
await page.goto('https://playwright.dev');
await expect(page).toHaveTitle(/Playwright/);
});
test('HTML reporter example', async ({ page }) => {
await page.goto('https://github.com');
await expect(page).toHaveTitle(/GitHub/);
});
test('JSON reporter example', async ({ page }) => {
await page.goto('https://www.wikipedia.org');
await expect(page).toHaveTitle(/Wikipedia/);
});
Letās explore how each reporter worksāand what the output looks like š
š 1. List Reporter
npx playwright test --reporter=list
š§¾ Output: A clean list of each test with its status and time taken.
ā Great for local debugging and readable summaries.
ā« 2. Dot Reporter
Each dot represents a test, and failed tests show as F.
npx playwright test --reporter=dot
ā” Fast, minimal, perfect for CI terminals or massive test suites.
š 3. Line Reporter
npx playwright test --reporter=line
It shows real-time updates of tests as they runāvisually pleasing and useful in CI logs.
š 4. HTML Reporter
npx playwright test --reporter=html
npx playwright show-report
š A beautiful, clickable HTML report showing:
- Test names, status, duration
- Ability to view traces and errors
- Great for debugging failed tests
šÆ Ideal for team collaboration or sharing detailed results with stakeholders.
š§¾ 5. JSON Reporter
npx playwright test --reporter=json
š Output: A structured json file with full test metadata.
š To specify file location, use config like:
reporter: [['json', { outputFile: 'results/report.json' }]]
š” Use this to:
- Build custom dashboards
- Feed test data into analytics tools
- Automate monitoring/reporting
š§Ŗ 6. JUnit Reporter
npx playwright test --reporter=junit
šļø Produces an XML file compatible with tools like Jenkins, CircleCI, and GitLab CI.
š To specify output file:
reporter: [['junit', { outputFile: 'results/junit-results.xml' }]]
ā Best for CI/CD integrations that expect standardized XML format.
āļø Configuring Reporters in playwright.config.js
Instead of passing reporters via CLI each time, you can configure them once in your playwright.config.js file:
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'],
['html'],
['json', { outputFile: 'results/report.json' }],
['junit', { outputFile: 'results/junit-results.xml' }]
]
});
Now just run:
npx playwright test
š” Your test run will generate all configured reports in one go!
ā Final Thoughts
Choosing the right reporter isnāt just about pretty outputāitās about clarity, debuggability, and team collaboration.
- š Start with html for local devs
- āļø Use junit or json in CI
- š Combine reporters for the best of all worlds
Let me know which reporter is your favoriteāor if youāve used these in creative ways.
Thanks for reading and happy testing with Playwright! šš
Comments
Post a Comment