How to diagnose flaky Playwright tests
A flaky Playwright test fails on its initial run and passes on a retry. Compare a passing and failing attempt before changing the test. Common causes include shared data, unstable locators and assumptions about timing.
Skaybase
Use retries to expose the pattern
Start by repeating the smallest affected test locally. Capture the failing trace, browser and environment. If it only fails in CI, compare parallelism, data fixtures, locale and other environment differences.
Playwright’s retry labels help distinguish tests that always pass, tests that pass after a retry, and tests that still fail. Keep that distinction in your report.
npx playwright test checkout.spec.ts --repeat-each=12 --trace retain-on-failureCheck what the user is waiting for
- Wait for a meaningful state such as a visible confirmation or an enabled control.
- Prefer a role or a stable test ID over a position in the DOM that can change.
- Give each test isolated data and check parallel workers for accidental sharing.
- Keep the failure trace after a retry succeeds, and include failed attempts out of total attempts.
Example: one test passed after three attempts
If payment is still pending on the first two attempts, note the observed condition and when it appears. If the UI never becomes ready, report that behavior separately from the fragile assertion.
Verify a change in the same conditions that produced the flake. Repeat with the original parallelism and data setup before treating the case as stable.