Back to cheat sheet hub

Playwright Test Runner Cheat Sheet

A compact guide to the Playwright test runner, covering the features that make suites reliable, readable, and CI-ready.

Playwright Module 5 Fixtures + config Debugging + reports

Main purpose

Use the runner to keep execution, setup, reporting, and debugging consistent across the whole suite.

Default habit

Put shared behavior in config or fixtures instead of repeating setup in each test.

Best fit

Strong for parallel execution, CI pipelines, browser matrices, and typed fixtures.

Pair it with

Use this together with the Playwright CI/CD and Playwright API sheets.

Minimal Config

Centralize retries, reporters, and browser projects in one place.

import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  retries: 1,
  reporter: 'html',
});

Projects

Projects let you run the same suite across browsers and device presets.

projects: [
  { name: 'chromium', use: { browserName: 'chromium' } },
  { name: 'firefox', use: { browserName: 'firefox' } },
]

describe and Hooks

Group related tests and keep setup scoped to where it belongs.

test.describe('login', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/login');
  });
});

Fixtures

Fixtures keep setup reusable and make dependencies explicit.

const test = base.extend({
  adminPage: async ({ browser }, use) => {
    const page = await browser.newPage();
    await use(page);
    await page.close();
  },
});

Parallel Execution

Parallelization is powerful, but it assumes tests are isolated and independent.

export default defineConfig({
  fullyParallel: true,
  workers: 4,
});

Retries and Timeouts

Use retries carefully for noise, not to hide real instability.

export default defineConfig({
  retries: 2,
  timeout: 30_000,
});

test.slow();

Reporters

Pick reporters that help developers and CI consumers read failures quickly.

reporter: [
  ['html'],
  ['json', { outputFile: 'results.json' }],
]

Annotations

Annotations help classify temporary or known execution behavior.

test.skip();
test.only();
test.fixme();
test.slow();

Parameterized Tests

Use data-driven loops to cover variants without copy-pasting entire tests.

for (const role of ['admin', 'student']) {
  test(`login as ${role}`, async ({ page }) => {
    await page.goto(`/login?role=${role}`);
  });
}

Debugging Tools

Use the runner’s built-in debugging features before inventing manual workarounds.

npx playwright test --debug
npx playwright show-report
npx playwright show-trace trace.zip