The CI summary said the checkout test passed. The log told a different story: on the first attempt, Playwright waited five seconds for Order confirmed and never saw it. On the retry, the text appeared almost immediately. The pull request had a green check, and the only trace came from the attempt that worked.
That is the wrong evidence to keep. A retry tells you whether a failure repeats under a fresh attempt. It does not explain the original failure, and it should not turn an unreliable test into a reliable-looking check. Keep the trace from the first failure, and make the required CI check fail when a test passes only on retry. Those are separate settings. You need both.
The Problem: The Trace Starts One Attempt Too Late
Playwright’s on-first-retry trace mode is a reasonable default when you care about recording overhead. It skips the initial attempt and records the first retry. If both attempts hit the same bug, the retry trace gives you something useful. If the bug disappears, you get a detailed account of a healthy run.
That distinction matters when the browser is waiting on a chain of events. A click starts a request; the response arrives; the application renders a new state. An assertion timeout only tells you what Playwright failed to observe by the deadline. It does not tell you which part of the chain broke. For that, I want the network requests, action timeline, and DOM snapshots from the attempt that timed out.
Use retain-on-failure for this job. Playwright records each attempt and discards traces from successful ones. In a fail-then-pass run, you keep the failed attempt’s trace rather than the retry’s. There is a cost: passing tests still pay for recording, even though their trace files are discarded. Measure job duration before making this the default across a large browser matrix.
Give the Retry a Job, Not a Vote
Here is a playwright.config.ts for a Next.js project with @playwright/test 1.56 installed, a dev script that runs next dev, and browser specs in tests/e2e. Commit the dependency and lockfile so CI uses the same Playwright version as local development.
With these settings, a clean first attempt passes the check. A failed attempt followed by a pass is classified as flaky and still produces a nonzero exit code in CI. Two failed attempts produce a failed test, with a trace from each. Locally, you get the original failure immediately, without spending time on a retry you did not ask for.
Playwright discards the worker process and browser after a test failure. The retry therefore does not start in precisely the same conditions. The application server can still be warm, and records written by the failed attempt can still exist in the database. A passing retry proves that the journey succeeded under the retry’s conditions. It does not prove that the first failure was harmless.
Make the Report Survive the Failed Job
The workflow needs to preserve the evidence without suppressing the exit code. This .github/workflows/e2e.yml installs Chromium and uploads the HTML report even when Playwright fails. Make the browser-tests job a required check in your branch protection rules if this policy is meant to block merges.
There is no continue-on-error on the test step. The condition on the upload step lets it run after a failure without changing the job’s result. if-no-files-found: ignore avoids a second, misleading error if dependency installation failed before Playwright wrote a report. Once you download and extract the artifact, open it with npx playwright show-report ./playwright-report and select the failed attempt, not the retry.
Treat that artifact like a diagnostic log with more context than usual. Traces can contain request data, DOM content, and anything sensitive your test rendered on screen. Run the suite with test accounts and synthetic records. A short retention period limits how long the artifact sticks around; it does not make production data safe to capture.
Read the Failed Attempt From the Last Known Good Action
I start one action before the red line. For the checkout example, inspect the Place order click and the events that follow. If no order request appears, look at the page snapshot for validation messages or an unexpected route before adding any waits. If the request returns a 500, start with the server error rather than rewriting the confirmation locator. If it returns a 201 but the confirmation never renders, inspect the response and browser console before deciding whether the application or the assertion is wrong.
Then use the retry as a comparison. If the first attempt gets a 409 and the retry succeeds, compare the inputs and responses before blaming runner speed. If only a cold attempt times out and the successful retry finishes after the server has warmed up, measure startup and request latency separately. Increasing the assertion timeout without making that distinction changes what CI tolerates, not what you know.
Start with the browser job your team already reruns most often. Enable retain-on-failure, allow one retry, and turn on failOnFlakyTests. In a disposable branch, force a test to fail only on its initial attempt. Check that the job stays red, the HTML report marks the test flaky, and the first attempt’s trace opens. That is the contract worth testing: when the failure disappears, the evidence does not.
No comments yet. Be the first to share your thoughts!