Skip to content

Playwright JSON Report Not Generating Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Playwright JSON Report Not Generating Fix. We cover key concepts, practical examples, and best practices.

Your CI pipeline expects JSON test results but Playwright doesn't generate them — or the output file is empty.

The Problem

# WRONG — JSON reporter configured without output file
npx playwright test --reporter=json
# The JSON is printed to stdout, not saved to a file

The JSON reporter outputs to stdout by default. CI tools often expect a file.

Step-by-Step Fix

1. Configure JSON reporter with output file

// RIGHT — playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['json', { outputFile: 'test-results.json' }],
  ],
});

2. Combine with HTML reporter

// RIGHT — multiple reporters
export default defineConfig({
  reporter: [
    ['html', { open: 'never' }],
    ['json', { outputFile: 'test-results/results.json' }],
    ['junit', { outputFile: 'test-results/junit.xml' }],
  ],
});

3. Use JSON for CI integration

# RIGHT — CI script
npx playwright test --reporter=json > test-results.json

# Or with config
npx playwright test

4. Parse JSON results programmatically

// RIGHT — read and process JSON results
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('test-results.json', 'utf8'));

console.log(`Total: ${results.stats.expected + results.stats.unexpected}`);
console.log(`Passed: ${results.stats.expected}`);
console.log(`Failed: ${results.stats.unexpected}`);

Expected output:

{
  "config": { ... },
  "suites": [
    {
      "title": "login flow",
      "specs": [
        {
          "title": "should login successfully",
          "ok": true,
          "tests": [
            {
              "status": "expected",
              "duration": 1234
            }
          ]
        }
      ]
    }
  ],
  "stats": {
    "expected": 12,
    "unexpected": 0,
    "flaky": 0,
    "skipped": 0
  }
}

Prevention Tips

  • Set outputFile for the JSON reporter
  • Use absolute or config-relative paths
  • Combine JSON with other reporters for different needs
  • Parse JSON results in CI for custom reporting
  • Use JUnit reporter for legacy CI integration

Common Mistakes with report json

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world PLAYWRIGHT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What schema does the JSON report use?

The JSON report contains config, suites (nested with specs and tests), and stats. Each test has status, duration, errors, and annotations. The full schema is documented in Playwright's source.

Can I use JSON reporter for real-time results?

The JSON reporter outputs results after all tests complete. For real-time results, use the line or list reporter. The JSON report is meant for post-run analysis.

How do I integrate JSON results with Allure?

Use the Allure Playwright adapter (@<a href="/testing-qa/playwright/">playwright</a>/test Allure integration) or write a script to convert the JSON report to Allure-compatible XML format.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro