← All questions

How do I stop my Playwright tests being flaky in CI but not locally?

Asked 2026-08-12Viewed 51 times2 answers
4

My suite passes every time on my laptop, but roughly one run in four fails in GitHub Actions — always on a different test, usually a timeout waiting for a button.

I have already tried bumping the global timeout to 60s, which reduced but did not eliminate the failures. Retries hide it, but that feels like cheating.

What actually causes this gap between local and CI, and how do I fix the root cause rather than masking it?

  • Are you running with fullyParallel: true? That made a big difference for us. Sofia Marquez
sign in to comment

2 Answers

2

✓ Accepted answer

The gap is almost always resources and timing, not Playwright. CI runners are slower and heavily contended, so anything that was "fast enough" locally becomes a race.

Three things fix the majority of cases:

  • Never wait on time, wait on state. Replace waitForTimeout with web-first assertions like await expect(locator).toBeVisible() — they retry automatically.
  • Kill shared state between tests. If tests share a user or a database row, parallel workers in CI will collide. Give each test its own fixture data.
  • Record a trace on first retry (trace: 'on-first-retry') so you can actually see the failure instead of guessing.

On retries — keep them on, but treat every retry as a bug ticket rather than a pass. A test that only passes on retry is telling you something real.

answered 2026-08-12
3

Adding to the above: check whether your CI browser is running headless while you test headed locally. Headless Chromium has a different default viewport, which silently changes which elements are in view and whether lazy-loaded content has rendered.

Run headed locally with --headed off to reproduce, or pin the viewport explicitly in your config.

answered 2026-08-12

Your answer

Sign in to post an answer.