A test that passes on retry has produced two different outcomes under apparently similar conditions. Increasing retries can make the pipeline greener while leaving the cause unresolved. Preserve the first failure and identify the changed condition before deciding whether retry is an appropriate recovery policy.
An intermittent export-download failure is the running example. Follow its first-failure evidence through synchronization, shared storage, and Playwright worker replacement. The underlying defect may be in the test, the application, or their shared environment; the diagnosis must distinguish those possibilities.
Preserve the first attempt as evidence
Keep the assertion result, sanitized application logs, relevant trace, runtime versions, commit identity, and execution configuration. Record worker count, test order or seed when available, and whether the test shared external resources with other jobs.
The Playwright retry documentation distinguishes tests that pass initially, pass only after retry, and continue failing. Preserve those categories in reporting. Combining first-attempt and eventual success into one pass metric removes information needed to judge suite reliability.
Protect captured artifacts. Browser traces, screenshots, and network records can contain session data or personal information. Use synthetic test accounts and configure collection, access, and retention so the diagnostic process does not create a new data exposure.
Give the failure an initial hypothesis without claiming certainty. For a synthetic export test, the download may be delayed, the export may actually fail, or another test may remove its data. Those explanations imply different fixes even if they produce the same final assertion failure.
Classify the changing condition
Separate application nondeterminism, test synchronization, shared state, runner capacity, and external dependency behavior. More than one can contribute, but start with a hypothesis that has a distinguishing observation.
For synchronization, identify the event the test should wait for. A visible success message may precede durable job completion. A network response may precede the interface update the assertion needs. Choose an observation connected to the behavior being verified rather than an arbitrary pause.
For shared state, map database records, files, ports, accounts, and cached application state. A test that passes alone and fails in the suite suggests an interaction, but that result does not identify which resource is shared. The integration isolation guide provides a resource inventory method.
For capacity problems, compare the application's and runner's signals during failure. A slow CI worker can expose a legitimate timeout policy issue or simply reveal a test's unrealistic timing assumption. Determine which budget was exceeded before increasing it.
Change one variable in a bounded reproduction
Repeat the failing scenario with a fixed source revision and synthetic data. Change one relevant variable at a time: concurrency, order, dependency latency, clock control, or resource isolation. Preserve both successful and failed observations so the comparison remains reviewable.
Do not claim a flake rate from a small convenience sample. A few successful repetitions can support a narrow reproduction finding without establishing that the defect has disappeared. State what conditions were exercised and which remain untested.
Playwright can replace a worker after a failure, rerunning relevant setup in a new process. That means a retry may differ in more than elapsed time: process state, browser state, and setup execution can change. Inspect what survives outside the worker before interpreting retry success as evidence that a delay fixed the issue.
When the minimal reproduction points to a real application race, preserve it as a regression case at the appropriate layer. A browser test may reveal the symptom while a controlled service or database test provides more precise coverage of the concurrency mechanism.
Replace sleeps with meaningful synchronization
For a download test, the event subscription has an ordering requirement. Register interest in the download before triggering the click. If the click is awaited first and the listener is installed afterward, a fast download can occur between the two operations and the test may wait for an event that has already happened. Playwright's event waiting API documents the pattern of starting the wait before the trigger.
The useful conceptual sequence is: identify the export created by this test, subscribe to its expected download event, trigger that export's download action, await the event within the test budget, then verify the output belongs to the same export. A longer sleep does not repair a missed subscription. Waiting for any download can also pass on an unrelated export, so correlation remains part of the assertion.
For the background job before the download, choose an equally specific signal. A 202 Accepted response establishes that work was accepted under the API's contract, not that the export completed. The test can wait on the job's documented terminal state and inspect a terminal failure immediately rather than spending the whole timeout waiting for a success button that will never appear.
Use supported assertions or event observations that wait for the intended state within a bound. For the synthetic export, distinguish job acceptance, job completion, and downloadable output. Assert the transition relevant to the user task and report which transition failed.
Avoid broad waits that accidentally accept the wrong object. A page containing any completed export is insufficient when the test created a specific export. Carry the synthetic operation identity through the fixture and verify the result associated with that operation.
Control time-dependent logic where appropriate using the controlled clock guide. Preserve bounded integration tests for timing owned by external systems. A fake application clock cannot make a real broker lease expire unless that broker participates in the same control.
Keep cleanup reliable after assertions fail. Failed tests often leave exactly the state that breaks the next attempt. Cleanup should target the test's owned resources, preserve useful failure artifacts first, and avoid deleting shared data to make the next run pass.
Use retries and quarantine with an owner
Suppose a synthetic investigation produces these observations: 20 isolated runs pass, 6 of 20 parallel runs fail, and all failures show another worker removing the shared export directory before the download completes. Those numbers are an illustrative evidence record, not measured results or a claim about general flake rates. The useful distinction is that the failure trace identifies a shared resource and a competing cleanup action.
A candidate fix gives each test an owned export directory and scopes cleanup to that directory. Verify it by deliberately overlapping one test's cleanup with another test's download, then repeat the normal parallel arrangement. Reducing the entire suite to one worker might hide this interaction, but it does not establish that the shared cleanup is correct. Conversely, if isolated runs also fail with the same trace, the parallel-worker hypothesis is incomplete.
Retain the first-failure trace even when a retry passes. Under Playwright's worker replacement behavior, the new attempt may receive fresh process and browser state while an external database or filesystem remains shared. That is why retry success changes the evidence to explain; it does not erase the failed observation.
A bounded retry policy may keep an investigation from blocking unrelated work, but report the initial failure and assign follow-up ownership. Decide which failures may retry and how much total pipeline time they can consume. Do not retry a destructive external operation unless its test environment and duplicate behavior support it.
If temporary quarantine is necessary, retain execution and visibility where practical. Record the affected capability, owner, restoration condition, and the evidence that replaces its missing release signal. A skipped test without those details becomes an undocumented coverage gap.
After a fix, exercise the original triggering conditions and the normal suite arrangement. Verify first-attempt behavior, not just eventual success. Inspect whether the fix weakened the assertion or bypassed the behavior the test was created to protect.
Keep the original overlapping cleanup/download case in the regression suite and review first-attempt failures after the fix. If the same signature returns, reopen that mechanism. If a new signature appears, preserve it as a new observation rather than increasing retries under the assumption that every intermittent failure has the same cause.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit