Playwright Test Logs Reporter
pw-test-logs-reporter is a specialized Playwright test reporter designed to automatically send details of failed test cases to a configurable external API endpoint. Currently at version 1.0.1, this package offers a simple, purpose-built solution for integrating Playwright's test results into external logging or incident management systems, with a specific focus on capturing and reporting only test failures. It integrates directly into Playwright's configuration via a string reference in the `reporter` array, and requires the `FAILED_TEST_RESULTS_ENDPOINT` environment variable to be set for operation. Its release cadence is likely stable and infrequent, given its targeted functionality. It differentiates itself by its singular focus on failed tests and straightforward API reporting, providing a lean alternative to more comprehensive, all-encompassing reporting solutions.
Common errors
-
Reporter "pw-test-logs-reporter" cannot be found.
cause The package `pw-test-logs-reporter` is either not installed or Playwright cannot resolve its path.fixRun `npm install pw-test-logs-reporter` or `yarn add pw-test-logs-reporter` to install the package. Verify that it's listed in your `node_modules` and accessible to Playwright. -
Error: FAILED_TEST_RESULTS_ENDPOINT environment variable is not set.
cause The reporter class relies on the `FAILED_TEST_RESULTS_ENDPOINT` environment variable to determine where to send the failed test logs.fixSet the `FAILED_TEST_RESULTS_ENDPOINT` environment variable in your shell or CI/CD pipeline. For example, `export FAILED_TEST_RESULTS_ENDPOINT='http://your.api.com/logs'` before running your Playwright tests. -
TypeError: Cannot read properties of undefined (reading 'default')
cause This typically occurs in a CommonJS environment when trying to `require()` a package that uses a default export without specifying `.default`.fixIf using `require()`, ensure you access the default export correctly: `const PwTestLogsReporter = require('pw-test-logs-reporter').default;`.
Warnings
- gotcha The `FAILED_TEST_RESULTS_ENDPOINT` environment variable is mandatory for the reporter to function correctly. If this variable is not set, the reporter will likely fail to send any test results, and may throw an error or warning during the test run.
Install
-
npm install pw-test-logs-reporter -
yarn add pw-test-logs-reporter -
pnpm add pw-test-logs-reporter
Imports
- PwTestLogsReporter
import { PwTestLogsReporter } from 'pw-test-logs-reporter';import PwTestLogsReporter from 'pw-test-logs-reporter';
- PwTestLogsReporter (type)
import type { PwTestLogsReporter } from 'pw-test-logs-reporter'; - PwTestLogsReporter (CommonJS)
const PwTestLogsReporter = require('pw-test-logs-reporter');const PwTestLogsReporter = require('pw-test-logs-reporter').default;
Quickstart
import { defineConfig } from '@playwright/test';
const FAILED_ENDPOINT = process.env.FAILED_TEST_RESULTS_ENDPOINT ?? 'http://localhost:8080/api/failed-tests';
// playwright.config.ts
const config = defineConfig({
testDir: './tests', // Specify your test directory
reporter: [
["list"], // Standard list reporter
["pw-test-logs-reporter"]
],
use: {
// Base URL to use in actions like `await page.goto('/')`.
baseURL: 'http://127.0.0.1:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: {
browserName: 'chromium',
},
}
]
});
export default config;