TL;DR

Bucket a flaky test by the error its failed attempt threw, not by what the retry did. Launch errors, crashes and server startup failures go to infrastructure even when the retry passed, and only a failure that came from the test's own steps goes to the flaky bucket.

  1. Capture evidence first: CI-only retries, retain-on-failure traces and a JSON report from every run.
  2. Check the run: a missing report or a 'timedout' status means infrastructure.
  3. Check attempts across the run: many timedOut or interrupted attempts mean infrastructure.
  4. Read the failed attempt of every 'flaky' outcome: launch errors, crashes and startup failures are infrastructure, and failures in the test's own steps are flakes.
  5. Treat failure on every attempt as a regression candidate: reproduce it with --last-failed and read its trace.

A Playwright run goes red in CI, and the badge looks the same whatever went wrong. A test may be flaky. The app may have a real regression. Or something under the tests broke: the runner ran out of memory, the browser crashed, the web server never came up, a network call failed or an install went wrong. Each of those needs a different next action.

The tempting shortcut is "it passed on retry, so it's a flake." That rule files a browser crash or an out-of-memory runner as a flaky test, because the retry ran in a fresh worker with a fresh browser and passed. It also lets a regression that fails only some of the time get retried back to green. Every misfiled failure costs triage time twice: once chasing the wrong cause, and again when the real one comes back.

Playwright's reporter API keeps the results of each run of a test. Each result records its status and the errors thrown during the test. With trace: 'retain-on-failure', Playwright records a trace for every run but keeps it only for runs that failed, even when a later retry passes. Read that evidence in a fixed order, and every red run lands in one bucket with one next action.

How Playwright labels a failure

Playwright decides that a test is flaky from its retries, and failing tests are not retried by default. Once you turn retries on, Playwright reruns a failing test until it passes or reaches the maximum number of retries.

Retries give a failing test one of two labels. A test that failed on the first run and passed on a retry is flaky. A test that failed on the first run and on every retry is failed. In the reporter API, a test case's outcome is 'skipped', 'expected', 'unexpected' or 'flaky', and a test that passes on a second retry is 'flaky'.

The outcome summarizes the whole test. Each attempt also has its own status: passed, failed, timedOut, skipped or interrupted. Triage should read every attempt, because a flaky test whose failed attempt timed out tells a different story from one whose failed attempt hit a broken assertion.

What a pass on retry proves

After any failure, Playwright discards the whole worker process along with its browser and starts a new worker. With retries on, that new worker starts by retrying the failed test. The retry runs in a clean process with a fresh browser, so a pass there shows the test can pass in a clean process, and that is all it shows.

The fresh worker has two consequences for triage. A browser that crashed on the first attempt gets a new browser for the retry, so a crash followed by a pass comes out labeled flaky. And a test that fails only under one CI condition, such as a slow backend, isn't flaky to Playwright until a retry passes. If the retry passes after the condition clears, Playwright labels the test flaky, since it failed on the first run but passed when retried.

Config that captures evidence

trace decides whether a trace is recorded for each test, and retries sets the maximum number of retry attempts a failed test gets.

Turn retries on in CI and leave them off locally. Without retries, Playwright never labels a test flaky, because the label needs a retry that passed.

Anti-pattern

Tracing only the first retry

By default the playwright.config file contains the configuration needed to create a trace.zip file for each test. Traces are set up to run on-first-retry, meaning they run on the first retry of a failed test.

// Anti-pattern: on-first-retry with retries unset, so CI never records a trace
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: 'list',
  use: {
    trace: 'on-first-retry',
  },
});

With on-first-retry, Playwright records a trace on the first retry of a failed test, not on the first run and not on the second retry. Failing tests are not retried by default, so this config never reaches a first retry, and CI records no trace at all. Turn retries on and you get a trace of the first retry, which for a test that passes on that retry is the attempt that passed. The first attempt, the one that failed, is never traced.

Fix

Use retain-on-failure. It records a trace for every run of a test and keeps it only for runs that failed, and a failed run's trace is kept even when a later retry passes.

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

export default defineConfig({
  // Retry only in CI: a pass on retry is what earns the flaky label
  retries: process.env.CI ? 2 : 0,
  // Fail the run on any flaky test, on the main branch only.
  // CI_BRANCH stands for whatever branch variable your CI exports.
  failOnFlakyTests: process.env.CI_BRANCH === 'main',
  reporter: [
    ['list'],
    ['json', { outputFile: 'results.json' }],
  ],
  use: {
    // Keep the failed attempt's trace, even when a retry passes
    trace: 'retain-on-failure',
  },
});

retain-on-failure records a trace for every run, as 'on' does, and the Trace Viewer docs call 'on' performance heavy. We'd still use it: the failed attempt's trace is the evidence every later step reads.

The two reporters split the work. list gives readable terminal output, and json writes a full JSON file with the test results.

failOnFlakyTests makes the run exit with an error if any test is marked flaky, and the docs call it useful on CI. Turn it on for main-branch CI once the flaky backlog is small enough that someone will act on each red run. On a branch with a long list of known flakes, every run goes red and the signal is gone.

A three-bucket triage order

Read a red run from the outside in: the run first, then the attempts across the whole run, then single tests. Infrastructure failures show up at the run level, so checking them first stops you from debugging a test that never had a working browser.

Missing report or timeout

First, check whether the run produced a report at all. A test run has no upper time bound by default, so a suite that hangs, or slowly grows past the CI provider's job limit, is killed by the runner mid-run and produces no report. If you set testConfig.globalTimeout, the reporter gets the run status 'timedout' instead, which means the global timeout was reached. Both cases are infrastructure: the suite didn't finish, and no single test result explains why.

Timeouts across the run

Second, look at attempt statuses across the whole run. One test with a timedOut attempt is a test problem. Many tests with timedOut or interrupted attempts in the same run point at the machine, not at many bugs that landed in one commit.

Flaky outcomes

Third, take the tests with the outcome 'flaky' and read the failed attempt's error before you file any of them. The evidence survives trimmed reports: with the reporters' onlyFailures option, flaky tests are still included even when they pass on retry, and every attempt of an included test is kept, successful retries too. The reporter docs mark a test that passed on retry with ±: "Passed on retry (flaky)".

Anti-pattern

Every retry pass is a flake

A run ends with a handful of tests marked flaky, and they go straight onto the flaky list because they passed the second time. Nobody opens the first attempt's error. A browser that failed to launch, a page that crashed when the runner ran out of memory and a server that came up late can all pass on a retry in a fresh worker, so they get filed as test problems while the runner keeps breaking.

Fix

Bucket a flaky test by the error its failed attempt threw, not by what the retry did. Launch errors, crashes and server startup failures go to infrastructure even when the retry passed. Only a failure that came from the test's own steps goes to the flaky bucket.

Failed on every attempt

Fourth, a test that failed on the first run and on every retry is a regression candidate. It isn't a confirmed regression until you reproduce it and read its trace.

A bucketing reporter

Do the sorting in a reporter rather than inside the tests: the reporter API already carries each test case's outcome and each attempt's status. The reporter below collects every attempt, buckets each test that didn't pass cleanly, flags a run that hit the global timeout and prints a summary when the run ends.

// triage-reporter.ts
import type {
  FullResult,
  Reporter,
  TestCase,
  TestResult,
} from '@playwright/test/reporter';

type Bucket = 'timeouts' | 'flaky' | 'regression';

// Tests with timedOut or interrupted attempts before a run counts as infra
const INFRA_THRESHOLD = 5;

class TriageReporter implements Reporter {
  private attempts = new Map<TestCase, TestResult[]>();

  onTestEnd(test: TestCase, result: TestResult) {
    const results = this.attempts.get(test) ?? [];
    results.push(result);
    this.attempts.set(test, results);
  }

  onEnd(result: FullResult) {
    const buckets: Record<Bucket, string[]> = { timeouts: [], flaky: [], regression: [] };

    for (const [test, results] of this.attempts) {
      const outcome = test.outcome();
      if (outcome === 'expected' || outcome === 'skipped') continue;

      // The first line of the first failed attempt's error is the signature
      const failed = results.find((r) => r.status !== 'passed');
      const signature = failed?.error?.message?.split('\n')[0] ?? failed?.status;
      const entry = `${test.titlePath().join(' > ')}: ${signature}`;

      if (results.some((r) => r.status === 'timedOut' || r.status === 'interrupted')) {
        buckets.timeouts.push(entry);
      } else if (outcome === 'flaky') {
        buckets.flaky.push(entry);
      } else {
        buckets.regression.push(entry);
      }
    }

    if (result.status === 'timedout') {
      console.log('Run hit the global timeout: treat it as infrastructure.');
    }
    if (buckets.timeouts.length >= INFRA_THRESHOLD) {
      console.log(`${buckets.timeouts.length} tests timed out or were interrupted: check the runner first.`);
    }
    for (const bucket of Object.keys(buckets) as Bucket[]) {
      console.log(`\n${bucket} (${buckets[bucket].length})`);
      for (const entry of buckets[bucket]) console.log(`  ${entry}`);
    }
  }
}

export default TriageReporter;

Playwright can use multiple reporters at the same time, so add this one to the reporter array next to list and json. INFRA_THRESHOLD is yours to tune: it's the number of timed-out or interrupted tests at which one run stops looking like separate bugs. A flaky test whose failed attempt timed out lands in timeouts, not flaky, on purpose: read its error before it joins the flaky list.

Signatures and next actions

SignatureBucketNext action
Job killed at the CI limit, no reportInfrastructureSet testConfig.globalTimeout, find the hang
Run status 'timedout'InfrastructureFind what slowed or hung the suite
Web server took longer to boot than its timeoutInfrastructureFix the app's boot in CI, or increase the timeout
Failed to launch browserInfrastructureRerun with DEBUG=pw:browser, check the image version
Many timedOut or interrupted attempts in one runInfrastructureCheck the runner first; in Docker, use --ipc=host with Chromium, which can otherwise run out of memory and crash
Outcome 'flaky', failed attempt crashed or couldn't launchInfrastructureFix the runner, don't add retries
Outcome 'flaky', failed attempt failed on its own stepsFlakyRead the trace, assign an owner
Failed on every attemptRegression candidateReproduce with --last-failed, read the trace

Infrastructure failure signatures

Infrastructure failures reach you through tests, which is why they get filed as test failures. Each one has a signature you can check before you open a test file.

Server startup

Playwright waits 60000 ms by default for the webServer process to start and become available. An app that boots slower than that on a CI runner never serves a page to any test, so the failure belongs to the environment. Fix the boot in CI, or raise the webServer timeout on purpose, knowing why the app needs longer.

Browser launch

For Failed to launch browser errors, rerun with DEBUG=pw:browser, which the Playwright CI docs call helpful for exactly that error. In Docker, check that the image tag matches your Playwright version first: if the Playwright version in the image doesn't match the version in your project, Playwright can't locate the browser executables.

Memory crashes

The Playwright Docker docs recommend --ipc=host for Chromium, which can otherwise run out of memory and crash. Playwright discards the worker and its browser after a failure and carries on in a new worker, so the crash doesn't stop the run. Expect a memory crash to show up as failures on tests that share nothing but the runner.

When a test passes locally and fails only in CI, check the runner before the test. A failure that goes away when fewer tests run at once points at the runner's capacity. So does a shard whose failures move to different tests from run to run.

Runs with no report

Set testConfig.globalTimeout below your CI provider's job limit, so a hanging suite ends with a 'timedout' status the reporter can record instead of being killed with no report. Watch total run time across runs too: a suite that creeps toward the job limit fails as infrastructure before any test breaks.

Network errors

Network errors need a second look before they go to whoever owns the network. One reporter showed that Playwright's API request client ignores the server's Keep-Alive timeout, so a reused socket can fail with ECONNRESET (#42698). They retested on 1.63.0 and a 1.64.0 alpha and said it still reproduces. The issue was closed as not planned. File that signature as infrastructure, and keep retries from absorbing it.

Anti-pattern

Retries over a broken runner

The run fails on a crashed browser or a server that boots slowly, so someone raises retries until the run goes green. The crash still happens. Now it lands in the report as a flaky test, and the flaky count climbs while the outage stays hidden.

Fix

Fix the runner, the image or the server startup, then rerun. Don't add retries for this bucket. These commands check the version match, the memory setting and the browser launch:

# The image tag must match the Playwright version the project uses
npm ls @playwright/test
# Run the suite in the matching image with --ipc=host so Chromium doesn't run out of memory
docker run --rm --ipc=host -v "$PWD":/work -w /work mcr.microsoft.com/playwright:v1.63.0-noble /bin/bash -c "npm ci && npx playwright test"
# Print browser launch logs for Failed to launch browser errors
DEBUG=pw:browser npx playwright test

Fixing the flaky bucket

What's left in the flaky bucket failed on its own steps and passed on a retry, with no infrastructure signature in the failed attempt. Fix it in how the test waits, not in its timeouts.

The Playwright docs say that if your tests are flaky, the fix is very likely not in the timeout settings. Auto-retrying assertions such as expect(locator).toHaveText() have their own timeout, 5 seconds by default, unrelated to the test timeout, so a longer test timeout gives them no extra time.

A timeout isn't always a timing problem, either. A maintainer reproduced the timeout and called it a Firefox-only bug: when a main-frame navigation fails and Firefox commits its network error page, load is never reported, so waiting for the load state waits out its timeout (#43341). The issue was closed as not planned. Open the failed attempt's trace before you call a Firefox load timeout a flake.

Anti-pattern

Sleeps and retry loops

A login test fails now and then, so it gets a fixed sleep before the form and a loop that tries the whole login again:

// Anti-pattern: a fixed sleep and a hand-rolled loop hide the race and slow the suite
import { test } from '@playwright/test';

test('user can log in', async ({ page }) => {
  for (let attempt = 1; attempt <= 3; attempt++) {
    await page.goto('https://example.com/login');
    await page.waitForTimeout(10000);
    await page.getByLabel('Email').fill('user@example.com');
    await page.getByLabel('Password').fill(process.env.TEST_PASSWORD ?? '');
    await page.getByRole('button', { name: 'Sign in' }).click();
    if (await page.getByRole('heading', { name: 'Welcome' }).isVisible()) return;
  }
  throw new Error('Login failed after 3 attempts');
});

The sleep waits ten seconds whether the page needs one or thirty, so the test gets slower and still fails on the day CI is slower than the sleep. The loop hides the race from Playwright as well: a pass on the loop's second try is still a pass on the first run, so Playwright reports the test as passed, not flaky.

Fix

Replace the sleep with locator actions and web-first assertions. The Playwright docs warn that tests that wait for time are inherently flaky, and recommend locator actions and web assertions that wait automatically.

import { test, expect } from '@playwright/test';

test('user can log in', async ({ page }) => {
  await page.goto('https://example.com/login');
  // Locator actions wait for the element on their own
  await page.getByLabel('Email').fill('user@example.com');
  await page.getByLabel('Password').fill(process.env.TEST_PASSWORD ?? '');
  await page.getByRole('button', { name: 'Sign in' }).click();
  // Web-first assertion: retries until the heading shows or its timeout ends
  await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
});

Delete the loop as well, and let Playwright's own retries do the retrying, where they can label the result.

Reading the failed attempt

Under retain-on-failure, the failed attempt's trace survives the passing retry, and the report keeps both attempts. Read the failure knowing the same steps passed one attempt later, and compare the failed attempt with the passing retry for what can differ between two runs of the same code: a step that ran before its data loaded, a locator that matched a different element, state another test left behind, test data that changed, an external service that answered slowly, or a parallel test touching the same records.

Use retries to detect flakes, never as the fix. Give every known flake an owner and a ticket, and quarantine it without hiding new failures. An @flaky tag and a separate job work as a holding pen only while someone owns that job; without an owner, the tag is where tests go to be forgotten.

Confirming a real regression

A test that failed on the first run and on every retry is a candidate, not a verdict. Reproduce it before you blame the app. Run the suite locally, then rerun only the failures with --last-failed:

npx playwright test
npx playwright test --last-failed

Because --last-failed only re-runs the failures, you can loop on the broken ones without editing the tests.

Then open the retained trace of the first failed attempt in the Trace Viewer, which shows the log, source, network, errors and console for each step of the test. Check it in this order:

  1. Read the error on the failing step, and what the step before it did.
  2. Check the network requests around the failing step for a backend call that errored.
  3. Check the console for errors the page threw.
  4. Scan the log for a step that took far longer than its neighbors.

A failing backend call or a console error from a service the app depends on sends the failure back to the infrastructure bucket. The test is reporting a broken environment, and the app code may be fine.

After an upgrade

When a consistent failure starts right after a Playwright upgrade, run the test on the old version too, since the regression can be in the browser rather than your app. One reporter's fullscreen request from a popup worked on 1.64.1 and failed after upgrading to 1.65.1 (#44288). They worked around it by bringing the popup to the front. The issue was closed as completed. Playwright 1.64 ships Chromium 156.0.8078.4, and 1.65 ships Chromium 158.0.8127.18.

Where retries stop helping

Retries are a detector, and every detection costs a run. The retry starts in a new worker process with a new browser, so every retry pays for that test again. We'd keep CI retries low for that reason.

Unless failOnFlakyTests is on, retries also wave through a regression that fails only some of the time: when it passes on the retry, the run goes green with one more flaky label. A browser crash that passes on retry gets the same label. A rising flaky count can therefore be an infrastructure trend rather than a drop in test quality, so check the failed attempts' errors before you blame the tests.

failOnFlakyTests turns those labels into red runs. Use it where someone will act on them, like the main branch, and keep it off PR branches, where it blocks authors on flakes they didn't write.

A single run's report has no history either. It can't tell a test that broke today from one that has flaked on and off for weeks. Past that point you need data from many runs.

Triage across many runs

Cross-run triage needs the data first. Upload the JSON report from every CI run as an artifact, with the upload step set to run even when the tests fail, since the failed runs are the ones you'll query.

Group failures by error signature across runs, using the first line of the failed attempt's error. The same signature on unrelated tests points at infrastructure. The same test failing with the same signature run after run is a known flake, and it should already have an owner.

Track two numbers over time: the flaky rate per test and the failure count per bucket. A flaky rate that climbs across the suite at once is a runner problem; one that climbs on a single test belongs to that test. A tag on a test records that someone noticed it once; the flaky rate shows whether it's getting worse.

Currents' Error Explorer classifies errors into categories that are mutually exclusive and describe why the test failed, and one of them, Infra / Misc, covers failures caused by environment or runtime errors. Error Explorer lets you distinguish between flaky UI selectors, network instability and true logic errors. AI Failure Analysis in Currents gives each failure one category, such as Flaky Test, Environment Error, Network Error or Timeout, and examines the Playwright trace when the failed attempt has one. Treat that category as a first answer, and check it against the trace.

The runbook in short

  1. Capture first: CI-only retries, retain-on-failure traces and a JSON report from every run.
  2. Check the run: a missing report or a 'timedout' status means infrastructure.
  3. Check attempts across the run: many timedOut or interrupted attempts mean infrastructure.
  4. Read the failed attempt of every 'flaky' outcome: launch errors, crashes and startup failures are infrastructure, and failures in the test's own steps are flakes.
  5. Treat failure on every attempt as a regression candidate: reproduce it with --last-failed and read its trace.

Infrastructure gets fixed, never retried. Flakes get an owner and a real wait condition. Regressions get reproduced, traced and handed to whoever owns the code.

Frequently asked questions

How do I analyze Playwright test failures in CI?

Read a red run from the outside in: the run first, then the attempts across the whole run, then single tests. Infrastructure failures show up at the run level, so checking them first stops you from debugging a test that never had a working browser, as the triage order explains.

What is a flaky test in Playwright?

A test that failed on the first run and passed on a retry is flaky. Playwright decides that a test is flaky from its retries, and failing tests are not retried by default. How Playwright labels a failure covers the outcomes the reporter API gives a test case.

Does passing on retry mean a Playwright test is flaky?

Not necessarily. The retry runs in a clean process with a fresh browser, so a pass there shows the test can pass in a clean process, and that is all it shows. A browser that crashed on the first attempt gets a new browser for the retry, so a crash followed by a pass comes out labeled flaky, as what a pass on retry proves explains.

Should Playwright retries be on in CI?

Yes: turn retries on in CI and leave them off locally. Without retries, Playwright never labels a test flaky, because the label needs a retry that passed. The settings are in config that captures evidence.

Which Playwright trace setting keeps the failed attempt?

Use retain-on-failure. It records a trace for every run of a test and keeps it only for runs that failed, and a failed run's trace is kept even when a later retry passes. With on-first-retry, the first attempt, the one that failed, is never traced, as tracing only the first retry shows.

How do I tell an infrastructure failure from a flaky test?

Bucket a flaky test by the error its failed attempt threw, not by what the retry did. Launch errors, crashes and server startup failures go to infrastructure even when the retry passed, and only a failure that came from the test's own steps goes to the flaky bucket, as every retry pass is a flake explains.

Will a longer timeout fix flaky Playwright tests?

Very likely not: the Playwright docs say that if your tests are flaky, the fix is very likely not in the timeout settings. Auto-retrying assertions such as expect(locator).toHaveText() have their own timeout, 5 seconds by default, unrelated to the test timeout, so a longer test timeout gives them no extra time. Fixing the flaky bucket covers fixing how the test waits instead.

How do I confirm a Playwright failure is a real regression?

Reproduce it before you blame the app: a test that failed on the first run and on every retry is a candidate, not a verdict. Run the suite locally, then rerun only the failures with --last-failed, and read the trace, as confirming a real regression describes.