Skip to content
Latchkey

How to Retry a Failed Playwright Test in CI

Playwright retries a failed test through the retries option, which the config commonly sets only when running in CI.

Set retries in playwright.config.ts, usually process.env.CI ? 2 : 0, and turn on trace: on-first-retry so a flaky run leaves a trace you can open.

Steps

  • Set retries in the Playwright config, gated on process.env.CI.
  • Enable trace: on-first-retry to capture evidence of the flake.
  • Review the flaky count in the report and fix the underlying wait.

Config

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

export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  use: { trace: 'on-first-retry' },
});

Open the trace of a flake

Terminal
npx playwright show-trace test-results/**/trace.zip

Gotchas

  • Playwright reports tests that passed on retry as "flaky", so read that count, do not ignore it.
  • Retries hide missing web-first assertions like expect(locator).toBeVisible(); add the wait instead.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →