THE REPLACEQA BLOG

Playwright tests pass on retry: what the result really means

Understand Playwright tests that pass on retry, preserve evidence from each attempt and choose a policy that keeps intermittent failures visible.

A Playwright test that fails and then passes on retry has produced two observations. The later pass shows that one attempt completed; it does not explain or erase the earlier failure. Keep both attempts visible and decide explicitly how your team handles that outcome.

Playwright labels a test that passes initially as passed, one that passes only after retrying as flaky, and one that exhausts its retries unsuccessfully as failed. Those labels describe execution history, not the root cause. See the retry documentation.

Separate three kinds of repetition

Before changing configuration, identify what is being repeated:

MechanismWhat repeatsWhat it tells you
An awaited web assertionObservation of an expected condition within its timeoutWhether that condition arrived in the allowed window
A whole-test retryThe test attempt and its relevant setupWhether another attempt completed
A rerun of the CI jobPotentially installation, services and many testsWhether a new job completed under its new conditions

These are not interchangeable repairs. If a report shows a different total after a second calculation, increasing the number of test retries does not establish that the first result was acceptable. Likewise, rerunning a job may reset state that was part of the original defect.

When retrying is useful for investigation, preserve the initial failure first. Compare the attempts rather than keeping only the most recent screenshot.

Reproduce a first failure and a later pass

The example package includes a small status page and this unchanged test:

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

test('status page reports ready', async ({ page }) => {
  await page.goto('/status');
  await expect(page.getByRole('heading', { name: 'Ready', exact: true })).toBeVisible();
});

The fixture's first-request mode serves “Unavailable” on the first document request to /status, then “Ready” on later requests. The test does not inspect its retry number or relax the assertion. This is a deterministic teaching fault, not a model of every real intermittent failure.

After extraction, run these commands in a Linux/macOS shell:

npm ci
npx playwright install chromium
DEMO_FAULT=first-request npx playwright test tests/retry.spec.js
DEMO_FAULT=first-request DEMO_RETRIES=1 npx playwright test tests/retry.spec.js

Each command starts a new fixture. With no retry, the first failure ends the run. With one retry, the next request receives the healthy page and the test passes on its second attempt.

The article's local Playwright Test 1.63.0 runs produced this matrix:

Application behaviorRetriesStrict flaky policyAttemptsExit code
Always ready1OffPass0
First request unavailable0OffFail1
First request unavailable1OffFail, pass0
First request unavailable1OnFail, pass1
Always unavailable1OffFail, fail1

The two middle retry rows observe the same application behavior. Only the policy for accepting a flaky result changes. Full recorded attempts are included in evidence.json in the archive.

Decide whether a flaky result should fail CI

Playwright supports failOnFlakyTests, which makes the run exit with an error if any tests are marked flaky. The configuration API reference documents the option. A strict configuration could include:

export default defineConfig({
  retries: 1,
  failOnFlakyTests: true,
  use: { trace: 'retain-on-failure' },
});

The package exposes that policy through environment variables:

DEMO_FAULT=first-request DEMO_RETRIES=1 DEMO_STRICT=1 npx playwright test tests/retry.spec.js

The retry still runs and supplies comparison evidence. A later pass does not make the overall command successful under this policy.

A strict policy is a reasonable starting point for a small set of important release checks. If a team temporarily accepts a known intermittent failure, make the exception specific: identify the test, owner, reason, issue and review date. A blanket “retry until green” practice leaves future reviewers unable to distinguish an understood exception from a new regression.

Do not use failOnFlakyTests as a diagnosis. A flaky classification could reflect an application race, inconsistent test data, an unreliable dependency or a mistaken assumption. The flag changes acceptance, not the explanation.

Keep the first failure's evidence

For this small demonstration, trace: 'retain-on-failure' retains evidence from failed attempts. Trace collection policies involve a storage and runtime tradeoff; choose one that preserves the attempt you need to investigate. Recording only a successful retry cannot reconstruct an earlier failure.

Save the run's source revision, environment, fixture state and attempt order alongside the artifacts. Before rerunning the packaged command, copy its result directory if you need to keep it. The included matrix runner preserves separate reports and artifacts under matrix-results/.

The trace investigation guide covers the inspection itself. For a stable failure caused by changed editorial content, see the dynamic-content guide; that problem may be reproducible rather than intermittent.

Verify a fix with independent executions

After repairing the cause, disable whole-test retries while checking repeatability. The package's healthy fixture can be exercised with:

npx playwright test tests/retry.spec.js --retries=0 --repeat-each=10

All ten healthy executions passed in the local demonstration. That is a bounded observation under one browser and environment, not proof that an intermittent failure can never recur. Choose additional conditions based on the suspected cause, such as parallel data access or the deployment environment that originally failed.

Keep a short team policy next to the tests:

DecisionExample policy for critical smoke checks
Number of diagnostic retriesOne
Acceptance of flaky resultsFail CI unless a specific temporary exception is reviewed
Evidence retainedFailed attempt, source revision and environment
OwnerThe person responsible for the affected journey
Fix validationRepeated independent runs, with sample and conditions reported

ReplaceQA retains individual validation attempts and their evidence for public journey tests. Its current activation rules are separate from the CI policy shown here. Explore the closed beta if that review workflow fits your team, and keep retry history attached to any result you rely on.

Keep checking your important customer journeys.

Explore ReplaceQA ↗