Playwright 23 ๐ญ Reporters โ HTML reporter, JUnit, and custom reporters
When automated test suites run locally or inside continuous integration pipelines, raw terminal text streams are rarely enough to diagnose complex failure states. Without rich evidenceโsuch as step-by-step action logs, captured screenshots, network traces, and structured machine-readable logsโidentifying why a test failed can turn into guesswork. Playwright solves this problem with an extensible reporting architecture capable of generating interactive human-readable dashboards, standard XML pipelines for CI integrations, and fully custom programmatic output handlers.
Mastering Playwright reporters involves configuring built-in formats, capturing rich debugging attachments, exporting XML metrics for dashboard ingestion, and implementing custom event-driven reporter classes. This chapter explores HTML reporter customization, JUnit XML generation, multi-reporter orchestration, and custom reporter authoring.
Key point: Playwright supports multiple concurrent reportersโsuch as the interactive HTML dashboard, machine-readable JUnit XML, and custom event handlersโallowing teams to tailor test visibility for both local debugging and CI pipelines.
Why X exists
The terminal log blind spot.
Linear console logs lose vital visual context, making it difficult to inspect page states, DOM structures, or network interactions at the exact timestamp of an assertion failure.
The CI dashboard integration requirement.
Continuous integration systems (such as Jenkins, GitLab CI, and Azure DevOps) require standardized, machine-readable XML result formats to render test analytics and build widgets automatically.
The multi-stakeholder visibility gap.
Developers require deep, granular debugging traces, whereas engineering managers and QA leads need high-level pass/rate trends and structured execution metrics.
The fragmented reporting tool overhead.
Legacy testing frameworks often require installing third-party plugins just to generate basic HTML reports or export test metrics, whereas Playwright provides robust reporting features out of the box.
The internal telemetry requirement.
Enterprise environments often need to stream real-time test outcomes directly into proprietary internal analytics tools or chat webhooks without parsing static file outputs manually.
a. Configuring and Customizing the HTML Reporter
Playwrightโs built-in HTML reporter generates a self-contained, interactive web dashboard that organizes test runs hierarchically. It embeds trace files, screenshots, and video recordings directly into the interface, allowing engineers to replay exact browser states step by step.
TypeScript
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['html', {
outputFolder: 'my-html-report',
open: 'on-failure', // Options: 'always', 'never', 'on-failure'
host: 'localhost',
port: 9323
}]
],
});
Bash
# Manually open a generated Playwright HTML report from disk
npx playwright show-report my-html-report
The HTML reporter’s open configuration property dictates browser launch behavior post-execution, defaulting to 'on-failure' so developers are greeted with visual debugging evidence immediately when tests break. Setting outputFolder ensures reports are written to clean, predictable directories for artifact archiving.
b. Generating JUnit XML Reports for CI Dashboards
Most continuous integration and test management tools understand JUnit XML formatting. Playwright’s built-in JUnit reporter converts test outcomes into standard XML schemas, making it easy to display test summaries natively inside pipeline interfaces.
TypeScript
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['junit', {
outputFile: 'test-results/junit/results.xml',
stripANSIControlSequences: true,
includeProjectInTestName: true
}]
],
});
Bash
# Generate JUnit report dynamically via CLI overrides
npx playwright test --reporter=junit
By exporting structured XML files via outputFile, CI platforms can parse test durations, failures, and suite groupings automatically without requiring custom parsing scripts.
c. Authoring Custom Programmatic Reporters
When built-in formats do not meet organizational requirements, Playwright exposes a robust Reporter API. By implementing the Reporter interface, developers can build custom event-driven handlers that react to test lifecycle hooks (onBegin, onTestBegin, onTestEnd, onEnd).
TypeScript
// my-custom-reporter.ts
import type { Reporter, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
class SlackNotificationReporter implements Reporter {
onTestEnd(test: TestCase, result: TestResult) {
if (result.status === 'failed') {
console.log(`[ALERT] Test failed: ${test.title} (${result.duration}ms)`);
// Trigger webhook notifications or custom logging here
}
}
onEnd(result: FullResult) {
console.log(`[SUMMARY] Test run finished with status: ${result.status}`);
}
}
export default SlackNotificationReporter;
TypeScript
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'],
['./my-custom-reporter.ts']
],
});
Custom reporters run concurrently alongside standard output streams, allowing teams to feed live execution data into internal monitoring pipelines or terminal formatters seamlessly.
Complete Example Session
TypeScript
// ============================================
// PART 1: MULTI-REPORTER CONFIGURATION SETUP
// ============================================
import { defineConfig } from '@playwright/test';
export default defineConfig({
reporter: [
['list'],
['html', { outputFolder: 'playwright-report', open: 'never' }],
['junit', { outputFile: 'results/junit.xml' }],
['./reporters/custom-metrics-reporter.ts']
],
});
TypeScript
// ============================================
// PART 2: PACKAGE SCRIPT CONFIGURATION
// ============================================
export const packageManifestScripts = {
"scripts": {
"test": "playwright test",
"test:ci": "playwright test --reporter=junit,html",
"report:show": "npx playwright show-report"
}
};
TypeScript
// ============================================
// PART 3: SAMPLE E2E TEST FILE (tests/checkout.spec.ts)
// ============================================
import { test, expect } from '@playwright/test';
test.describe('Checkout Flow Suite', () => {
test('completes purchase successfully', async ({ page }) => {
await page.goto('https://example.com/checkout');
await expect(page.getByRole('button', { name: /pay/i })).toBeVisible();
});
});
TypeScript
// ============================================
// PART 4: CUSTOM METRICS REPORTER IMPLEMENTATION
// ============================================
import type { Reporter, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
export default class MetricsReporter implements Reporter {
private failedCount = 0;
private passedCount = 0;
onTestEnd(_test: TestCase, result: TestResult) {
if (result.status === 'passed') this.passedCount++;
if (result.status === 'failed') this.failedCount++;
}
onEnd(result: FullResult) {
console.log(`\n=== CUSTOM METRICS REPORT ===`);
console.log(`Passed: ${this.passedCount} | Failed: ${this.failedCount}`);
console.log(`Status: ${result.status.toUpperCase()}`);
console.log(`=============================\n`);
}
}
TypeScript
// ============================================
// PART 5: ATTACHING ARTIFACTS PROGRAMMATICALLY
// ============================================
test('attaches custom log data on failure', async ({ page }, testInfo) => {
await page.goto('https://example.com');
const diagnosticData = JSON.stringify({ timestamp: Date.now(), url: page.url() });
await testInfo.attach('diagnostic-payload', {
body: diagnosticData,
contentType: 'application/json',
});
});
TypeScript
// ============================================
// PART 6: TRACE RECORDING CONFIGURATION FOR REPORTS
// ============================================
export const traceConfig = defineConfig({
use: {
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
});
TypeScript
// ============================================
// PART 7: RUNNING MULTIPLE REPORTERS SIMULTANEOUSLY
// ============================================
// Playwright executes all configured reporters in a single test run pass
TypeScript
// ============================================
// PART 8: PROGRAMMATIC REPORT MERGING UTILITY
// ============================================
import { mergeReports } from '@playwright/test';
import { resolve } from 'node:path';
async function generateMergedDashboard() {
await mergeReports(resolve('./all-sharded-blobs'));
}
TypeScript
// ============================================
// PART 9: JUNIT XML ENVIRONMENT VARIABLE OVERRIDE
// ============================================
// PLAYWRIGHT_JUNIT_OUTPUT_FILE=results/custom-junit.xml npx playwright test --reporter=junit
TypeScript
// ============================================
// PART 10: SESSION FINALIZATION
// ============================================
// Multi-format reporter pipeline initialized and validated successfully
Quick Reference
Built-in Playwright Reporters
| Reporter Name | Output Destination | Best Suited For |
list | Terminal stdout | Local development and active monitoring |
dot | Terminal stdout | Compact CI logs |
line | Terminal stdout | Clean single-line CI progress summary |
html | Self-contained folder | Interactive local debugging and artifact storage |
junit | XML file | CI dashboards (GitHub Actions, Jenkins, GitLab) |
json | JSON file | Downstream custom tooling integration |
blob | Archive directory | Sharded CI test result merging |
HTML Reporter Configuration Options
| Option Key | Type | Default | Purpose |
outputFolder | string | 'playwright-report' | Target directory for generated HTML assets |
open | string | 'on-failure' | Controls browser launch ('always', 'never', 'on-failure') |
host | string | 'localhost' | Hostname when serving report locally |
port | number | 9323 | Port binding when serving report locally |
Best Practices
โ Do This:
TypeScript
reporter: [['list'], ['html', { open: 'never' }], ['junit', { outputFile: 'results.xml' }]] // โ
โ Don’t Do This:
TypeScript
// rely on a single terminal reporter inside production CI pipelines // โ
โ Do This:
TypeScript
use: { trace: 'retain-on-failure' } // โ
โ Don’t Do This:
TypeScript
use: { trace: 'on' } // record heavy execution traces on every single test pass // โ
โ Do This:
TypeScript
reporter: process.env.CI ? [['junit', { outputFile: 'results.xml' }]] : [['html']] // โ
โ Don’t Do This:
TypeScript
// hardcode local browser auto-launch flags ('open: always') inside CI builds // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
| CI build hanging because HTML report tries to open | Leaving the HTML reporter default open setting active on headless servers | Set open: 'never' or use CI-specific reporter arrays |
| Overwriting XML reports in sharded runs | Multiple parallel CI shards writing to the exact same JUnit output file path | Append shard identifiers to filenames or use the blob reporter before merging |
| Missing trace attachments in HTML report | Disabling traces or failing to set outputFolder properly in configuration | Ensure trace: 'retain-on-failure' is enabled under use settings |
| Custom reporter runtime crash | Unhandled exceptions inside lifecycle methods (onTestEnd, onEnd) | Wrap custom logic in try/catch blocks to prevent disrupting test runner execution |
Real-World Examples
1. Configuring Multiple Built-In Reporters Simultaneously
TypeScript
export default defineConfig({
reporter: [
['list'],
['html', { outputFolder: 'playwright-report', open: 'never' }],
['junit', { outputFile: 'test-results/junit.xml' }]
],
});
2. Disabling HTML Report Auto-Launch for CI Workflows
TypeScript
export default defineConfig({
reporter: [['html', { open: 'never' }]],
});
3. Setting JUnit Output File via Environment Variables
Bash
PLAYWRIGHT_JUNIT_OUTPUT_FILE=reports/junit.xml npx playwright test --reporter=junit
4. Implementing a Custom Console Summary Reporter
TypeScript
import type { Reporter, FullResult } from '@playwright/test/reporter';
export default class SummaryLogger implements Reporter {
onEnd(result: FullResult) {
console.log(`Test run completed with status: ${result.status}`);
}
}
5. Registering a Custom Reporter File Path in Config
TypeScript
export default defineConfig({
reporter: [['./reporters/slack-notifier.ts']],
});
6. Attaching Custom Text Data to Test Results
TypeScript
test('submits form', async ({ page }, testInfo) => {
await testInfo.attach('form-payload', {
body: JSON.stringify({ user: 'test' }),
contentType: 'application/json',
});
});
7. Configuring Blob Reporter for Sharded CI Builds
TypeScript
export default defineConfig({
reporter: [['blob', { outputDir: 'blob-report-dir' }]],
});
8. Merging Sharded Blob Reports Programmatically
TypeScript
import { mergeReports } from '@playwright/test';
await mergeReports('./all-blobs', 'playwright-report');
9. Exporting JSON Results for External Analytics Tooling
TypeScript
export default defineConfig({
reporter: [['json', { outputFile: 'test-results.json' }]],
});
10. Enabling GitHub Actions Native Annotation Reporter
TypeScript
export default defineConfig({
reporter: process.env.CI ? [['github'], ['junit', { outputFile: 'results.xml' }]] : [['html']],
});
Visual
Multi-Reporter Execution Pipeline Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Playwright Test Runner Execution Engine โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ List Reporterโ โ HTML Reporterโ โ JUnit XML โ
โ (Terminal) โ โ (Browser UI) โ โ (CI Pipeline)โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
HTML Interactive Report vs. JUnit XML Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTML REPORT: Rich Traces, Screenshots & Step Timelines โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ JUNIX XML: Standardized Pass/Fail Metrics for CI Daemonsโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Custom Reporter Event Hook Lifecycle
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ onBegin() โโโบ Test Suite Initialization โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ onTestBegin() โโโบ Individual Test Execution Starts โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ onTestEnd() โโโบ Capture Status, Duration & Attachments โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ onEnd() โโโบ Generate Final Metrics & Terminate Run โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
| Concept | Test Reporting and Analytics in Playwright |
| Core Built-In Formats | list, html, junit, json, blob, github |
| HTML Reporter | Interactive web dashboard embedding traces and screenshots |
| JUnit Reporter | XML format for CI platform and test management ingestion |
| Custom Reporter API | Event-driven classes implementing the Reporter interface |
| Multi-Reporter Support | Run multiple formatters concurrently in a single test pass |
| CI Best Practice | Combine HTML for human review, JUnit for CI analytics, and Blob for sharded runs |
| Configuration Property | reporter array inside playwright.config.ts |
| Artifact Attachment | testInfo.attach() for custom diagnostic payloads |
| Programmatic Merging | mergeReports() utility for combining sharded test artifacts |
Key takeaways:
- Leverage multiple reporters. Configure a hybrid reporting setup (e.g., terminal list for local feedback, HTML for debugging, and JUnit XML for CI pipelines).
- Customize the HTML dashboard. Use output folders and set
open: 'never'to prevent blocking headless CI runs while retaining deep interactive trace inspection. - Export standard JUnit XML. Ensure your continuous integration environment parses test statistics natively by outputting structured XML logs.
- Build custom event handlers. Implement the Playwright
Reporterinterface to stream test outcomes into internal telemetry systems or chat webhooks. - Attach custom diagnostics. Use
testInfo.attach()to inject custom payloads, logs, or state snapshots directly into test execution reports. - Merge sharded outputs. Combine independent CI shard results into a single comprehensive HTML report using Playwright’s native blob reporter and
mergeReports().
Remember: Playwright reporters bridge the gap between raw test execution and actionable engineering intelligence. By orchestrating interactive HTML dashboards, CI-compatible JUnit XML files, and custom event handlers, development teams gain maximum visibility into application health across every stage of development.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!