Skip to main content
Ask AI

@testrelic/playwright-analytics

The main package that provides a custom Playwright reporter and enhanced test fixture for capturing navigation timelines and test analytics.

What does this package include?

What does the reporter capture?

The custom reporter collects comprehensive test data including:

  • Test results (pass/fail/flaky/skipped)
  • Execution timing and duration
  • Failure diagnostics with code snippets
  • Network request statistics
  • CI environment metadata
  • Navigation timeline reconstruction
  • Test steps and actions plus assertions, video-synced (includeActionSteps)
  • Browser console logs per test (captureConsoleLogs)
  • Assertion results from expect() (captureAssertions)
  • Screenshots and video artifacts (includeArtifacts)
API-only runs

A test that uses the API request fixture (no browser) is tracked as an API test and opens the API Session Workspace in the cloud — method, URL, status, headers, bodies, timing, and assertions. Unified tests (browser + API) show both the navigation timeline and the API details. The API fixture is available via the @testrelic/playwright-analytics/api-fixture subpath; see the Configuration reference for capture options.

What does the fixture track?

The enhanced test fixture extends Playwright's default page fixture to automatically track:

  • Page navigations (goto, link clicks, browser navigation)
  • SPA route changes
  • Hash changes
  • Navigation timing
  • Network requests per navigation

How do I install it?

Set up with an AI assistant

AI Prompt — Install and configure reporter
Install @testrelic/playwright-analytics in this Playwright project.
1. Run: npm install @testrelic/playwright-analytics
2. Add it to playwright.config.ts:
['@testrelic/playwright-analytics', {
outputPath: './test-results/analytics-timeline.json',
includeStackTrace: true,
includeCodeSnippets: true,
includeNetworkStats: true,
}]
3. In all test files, replace the import:
FROM: import { test, expect } from '@playwright/test';
TO: import { test, expect } from '@testrelic/playwright-analytics/fixture';
Show me the updated config and one updated test file.

AI Prompt — Merge shard reports
I have TestRelic shard reports at shard-1.json and shard-2.json.
Use mergeReports from '@testrelic/playwright-analytics/merge' to merge them into merged-report.json.
Write a short Node.js script I can run with: node merge.mjs

What does this package export?

The main entry point (@testrelic/playwright-analytics) exports the reporter class used by Playwright's reporter array, along with TypeScript types for the report schema.

Subpath exports:

SubpathWhat it provides
@testrelic/playwright-analyticsReporter class (used in playwright.config.ts)
@testrelic/playwright-analytics/fixtureEnhanced test + expect fixture with navigation tracking
@testrelic/playwright-analytics/api-fixturetestRelicApiFixture for extending API test fixtures
@testrelic/playwright-analytics/mergemergeReports function for merging shard reports
// Import the fixture in test files
import { test, expect } from '@testrelic/playwright-analytics/fixture';

// Import for programmatic shard merging
import { mergeReports } from '@testrelic/playwright-analytics/merge';
Loading chart…