· Engineering notes

Playwright flake quarantine in CI

When the PR gate flakes, teams stop trusting red. Use a dated quarantine policy, keep traces on failure, and ban waits that hide races - without turning skip into the default.

Assertwise lab: Playwright CI pipeline diagram
CI skeleton you already have - this post adds quarantine policy on top.

When the gate still fails but nobody trusts it

You already have a Playwright job on every PR. The failure mode that kills trust is not "no tests" - it is a red check that the team re-runs until green. Fix the policy before you add more scenarios.

This post assumes you have a fail-closed skeleton (config + GitHub Actions). If you do not, start with Playwright testing on every PR.

Artifact: quarantine decision table

For each flake ticket, pick exactly one row. Do not invent a fourth state called "we will watch it".

SignalActionGate behaviourExit criteria
Fails >1 in last 10 PR runs on mainline path; root cause known (<1 day fix)Fix now in the same PR or a blocker PRStay red until fixedGreen on 3 consecutive PR runs + one main run
Fails intermittently; root cause unknown; blocks unrelated PRsQuarantine with ticket + owner + dateExcluded from required job; still runs in a non-blocking jobTicket closed with fix or delete within 10 working days
Asserts something the product no longer promisesDelete the testRemoved from suiteChangelog note; no silent skip

Quarantine is a dated exception, not a parking lot. If the ticket ages past the exit date, the non-blocking job should fail the build until someone decides fix or delete.

Fail-closed quarantine (do not silent-skip)

  1. Tag the test: test.describe.configure({ tag: '@quarantine' }) or a project that filters grepInvert: /@quarantine/ on the required job.
  2. Keep a second workflow job e2e-quarantine that runs only @quarantine, uploads artifacts, and is not required for merge.
  3. Fail the required job if a quarantine tag has no open ticket ID in the test title (example: @quarantine TICKET-1842).
  4. Never use test.skip(true) without a ticket ID in the reason string.
// playwright.config.ts (required project)
projects: [
  {
    name: 'pr-critical',
    grepInvert: /@quarantine/,
    use: { ...devices['Desktop Chrome'] },
  },
]

Traces and HTML report only when useful

Always-on traces slow CI and bury signal. Use Playwright's recommended CI pattern: retain trace on failure, publish the HTML report as an Actions artifact.

# .github/workflows/e2e.yml (excerpt)
- name: Run Playwright
  run: npx playwright test --project=pr-critical
  env:
    PLAYWRIGHT_HTML_REPORT: playwright-report

- name: Upload report on failure
  if: failure()
  uses: actions/upload-artifact@v4
  with:
    name: playwright-report
    path: |
      playwright-report/
      test-results/
    retention-days: 14

In config: trace: 'on-first-retry', retries: process.env.CI ? 1 : 0. One retry is for network blips; two or more usually hides a real race. Official docs: test retries, trace viewer, CI guide.

Forbidden waits checklist

  • Ban waitForTimeout in new tests (lint or PR checklist). Prefer expect(locator).toBeVisible() / toHaveURL / toHaveResponse.
  • Ban naked page.waitForLoadState('networkidle') on SPAs that keep websockets open - it flakes by design.
  • Prefer role + name locators over CSS that mirrors implementation class names.
  • Seed data in beforeEach via API; do not click through setup that other tests already cover.
  • If a flake needs "sleep 2s" to pass, quarantine it and fix the race (missing await, animation, or shared account).

When this policy fails

Quarantine does not help if half the critical path is tagged. Cap quarantined tests (for example 2 on a 12-test gate). Above the cap, stop merging features until the oldest quarantine is closed. Also: comparing frameworks will not fix flakes - keep Selenium only when you must; see Playwright vs Selenium.

Related: wire suites into your repo under Test Automation & CI.

If you want this policy applied to your critical path, book a free 20-min test audit - leave with the three highest-risk flake sources on that path.