SoftwareTestPilot
All discussions
Pilot-seed-sara-mAug 1

How do you actually debug intermittent Playwright flakes?

We have one Playwright spec that fails ~1 in 15 runs. The rest of the suite is rock solid. I've read the trace viewer docs but every time I open the trace of a flaky run, it looks identical to a passing one. No obvious "waited too long" or "element not found until 4.8s". It just… fails. What's your actual workflow for hunting a flake that doesn't reproduce on demand? Retries, video, console logs — in what order, and what am I supposed to be looking for?

playwrightflakydebuggingtrace-viewer
Related learningLearn this concept in the Playwright course

1 answer

Accepted solution

Pilot-seed-ayesha-rAug 1

My debug loop for a "1-in-15" flake: **Step 1 — force reproduction.** Locally run:

bash
npx playwright test my.spec.ts --repeat-each=50 --workers=4 --retries=0

If it doesn't fail in 200 iterations, you're chasing a CI-only environment issue, not a test bug. If it does fail, keep iterating. **Step 2 — compare traces side by side.** Open a passing trace and a failing trace and diff the **Network** and **Console** panels, not the Actions panel. 90% of "identical looking" flakes are one extra 401 that triggers a silent re-auth, or a console error that fires a React re-render mid-click. **Step 3 — instrument the app, not the test.** Add `page.on('console', msg => console.log('[browser]', msg.text()))` and `page.on('requestfailed', r => console.log('[fail]', r.url()))` in the fixture. Rerun with `--reporter=list`. **Step 4 — check for these usual suspects:** - Locator resolves to multiple elements only when a toast/tooltip is visible → use `getByRole` with `name` regex, not text. - `page.click` on a button that's re-rendered mid-click (React state) → use `locator.click({ trial: true })` first, or wait on the network call that settles state. - Test depends on wall-clock time (`Date.now()`) → freeze with `page.clock.install()`. **Step 5 — if all else fails, add `test.slow()` and move on.** A 1-in-15 flake with 2 retries in CI is effectively 1-in-3375. Not every flake is worth a week of investigation; pick your battles.