Playwright Performance Testing Plugin

2.0.6 · active · verified Tue Apr 21

playwright-performance is a plugin for Playwright that enables detailed performance analysis of end-to-end test flows, including UI, API, or hybrid scenarios. It measures the 'apparent response time' of key user procedures within your application, helping identify bottlenecks and areas for optimization. The current stable version is 2.0.6, with recent updates introducing HTML chart generation. The library maintains an active release cadence, with a major breaking change in version 2.x.x simplifying its integration model. Its key differentiator is the seamless integration into Playwright's `test.extend` fixture system, allowing developers to easily add performance sampling to existing tests without significant refactoring, and providing configurable output options for results.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to extend Playwright's `test` object with performance fixtures, record startup times for multiple URLs, and assert on individual sample durations within an extended test.

import { test as base, expect } from '@playwright/test';
import extendPlaywrightPerformance, { PerformanceOptions, PlaywrightPerformance } from 'playwright-performance';

// Extend the Playwright test object with performance fixtures
const test = base.extend<PlaywrightPerformance, PerformanceOptions>(extendPlaywrightPerformance());

test.describe('Website Startup Performance', () => {
  test('should load GitHub and SourceForge within acceptable limits', async ({ page, performance }) => {
    // Sample startup time for GitHub
    performance.sampleStart('GH-startup');
    await page.goto('https://github.com/', { waitUntil: 'domcontentloaded' });
    performance.sampleEnd('GH-startup');

    // Sample startup time for SourceForge
    performance.sampleStart('SF-startup');
    await page.goto('https://sourceforge.net/', { waitUntil: 'domcontentloaded' });
    performance.sampleEnd('SF-startup');

    // You can also get individual sample times within the test
    const githubStartupTime = performance.getSampleTime('GH-startup');
    const sourceForgeStartupTime = performance.getSampleTime('SF-startup');

    // Assertions for performance metrics
    expect(githubStartupTime).toBeLessThanOrEqual(5000); // Expect GitHub to load in under 5 seconds
    expect(sourceForgeStartupTime).toBeLessThanOrEqual(8000); // Expect SourceForge to load in under 8 seconds

    console.log(`GitHub Startup Time: ${githubStartupTime}ms`);
    console.log(`SourceForge Startup Time: ${sourceForgeStartupTime}ms`);
  });
});

view raw JSON →