Speed up Playwright tests in GitHub Actions

Choose trace recording, retention, and artifact upload separately. on-first-retry records and keeps the first retry even if it passes. retain-on-failure records every attempt and keeps failed attempts, including failures followed by a successful retry. Upload retained diagnostics on successful retry runs when flake investigation matters.

ci.hygiene.playwright-artifactsstatic · checkable from the repo
How StarSling works

AI agents open the PR

StarSling agents run this exact audit on your workflows, apply the fix, and open a reviewable PR automatically.

Do this

Recording consumes time while tests run; retaining files consumes disk space; uploading compresses and transfers those files. trace: 'on-first-retry' limits trace recording to the first retry and requires retries to be enabled. trace: 'retain-on-failure' records every attempt, then discards successful-attempt traces. Video has its own configuration. A failure()-only upload skips a run that recovers on retry, even when a trace exists locally. The example uploads retained files on non-cancelled runs so that recovered failures remain available for investigation.

.github/workflows/e2e.yml
jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test
      # Configure retry-aware trace recording in playwright.config.ts.
      # Upload retained diagnostics even when a retry passes.
      - uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: playwright-report
          path: playwright-report/
          if-no-files-found: ignore
      - uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: test-results
          path: test-results/
          if-no-files-found: ignore

Avoid this

.github/workflows/e2e.yml
jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: npx playwright test
      - uses: actions/upload-artifact@v4
        with:
          name: playwright-report
          path: playwright-report/
      - uses: actions/upload-artifact@v4
        with:
          name: test-results
          path: test-results/

How to detect it

  1. Search Playwright config for unconditional capture: grep -n 'trace:\|video:\|screenshot:' playwright.config.* - a value of 'on' (rather than 'on-first-retry', 'retain-on-failure', or 'only-on-failure') means every run records, pass or fail.

  2. Inspect the upload-artifact conditions alongside the recording mode. A failure()-only gate skips recovered retries. Use !cancelled() when retained retry evidence should upload on both successful and failed runs; decide separately whether cancelled-run artifacts are needed.

  3. Search for the browser install step: grep -n 'playwright install' .github/workflows/*.yml - a bare npx playwright install --with-deps with no browser argument installs Chromium, Firefox, and WebKit even when the suite only targets one.

Tradeoffs and safety

  • on-first-retry only records once a test has already failed once and is being retried, so it needs retries configured above zero; with retries at zero, on-first-retry never fires and a failing test produces no trace at all.

  • on-first-retry records the first retry attempt regardless of whether that retry passes or fails, so it preserves useful evidence for a flaky test. retain-on-failure records every attempt, discards successful attempts, and retains failed attempts; choose it when failed-attempt evidence matters more than recording less.

  • The example uses !cancelled() to upload retained files after successful or failed test runs, including recovered retries. It can also upload reports from clean passing runs. Use failure() only when losing recovered-retry artifacts is acceptable; use always() if uploads should also run after cancellation.

  • Restricting the install to one browser (chromium) breaks a suite that runs cross-browser projects in playwright.config.* - check the config's projects list before narrowing the install command.

Verify it worked

Hand this prompt to your coding agent (Claude Code, Cursor, and the like) to run this audit and open the fix as a reviewable PR.

Prompt for your coding agent
Audit this repository's Playwright configuration and CI workflow for unconditional
artifact capture and fix what you find.

1. Read playwright.config.* and check the trace, video, and screenshot options. If any is
   set to 'on', propose changing trace to 'on-first-retry' (or 'retain-on-failure' if the
   repo does not configure retries) and video to 'retain-on-failure'.
2. Review upload conditions together with recording and retention. When recovered-retry
   diagnostics must leave the runner, use an expression containing !cancelled() for the
   report and test-results uploads and ignore missing files. Explain that this can upload
   reports on clean passing runs too. Use failure() only if that loss of flaky-run evidence
   is acceptable; decide cancelled-run retention separately.
3. Check the playwright install step. If playwright.config.* defines projects for only one
   browser, propose narrowing npx playwright install --with-deps to name that browser
   explicitly; if multiple browser projects are configured, leave the install as is.
4. Read the Playwright trace viewer, test configuration, and CI docs linked on this page
   before editing.
5. Show the full diff and open a pull request; do not apply changes blindly. In the PR
   body, state how to verify a clean pass, a fail-then-pass retry, and a final failure.
   Confirm retained diagnostics upload under the chosen policy and measure recording
   overhead separately from upload time.

Confirm the change landed

  1. Run the suite with all tests passing and confirm the upload steps complete harmlessly (or ignore missing files) when the selected recording mode produces no traces.

  2. With retries enabled for on-first-retry, force a test and its retries to fail; confirm the selected trace/video modes retain the expected attempts and the upload steps attach the files.

  3. Force one test to fail once and pass on retry; confirm the retry trace remains in test-results and the upload step still attaches it even though the job finishes green.

  4. Compare recording time, retained artifact size, and upload duration separately on a clean pass, a recovered retry, and a final failure. Confirm the chosen diagnostic coverage before judging the savings.

Go further

One fix, all of them, or forever.

You have the prompt for this one practice. Here is how much further you can take it, each step doing more for you than the last.

  1. Fix this one thing

    Copy the prompt above

    Hand OPT56 to your coding agent and fix it in your repo today.

  2. Fix everything, once

    Install the ci-speedup skill

    One prompt audits your whole repo against all 73 ci-speedup patterns (this one plus 72 more) and hands your agent every fix at once. Open source, MIT, runs locally.

  3. Keep it fixed, forever

    Install the StarSling GitHub App

    Connect GitHub and the fixes stay applied as your CI evolves, with agents that keep inspecting your workflows and opening optimization PRs you review.

Sources

1Playwright: trace recording and retention modes (opens in new tab)

2GitHub Actions: status-check expressions (opens in new tab)

3Playwright: Trace viewer (opens in new tab)

4Playwright: Test configuration (video, screenshot) (opens in new tab)

5Playwright: Continuous Integration (opens in new tab)

6Playwright: Browsers (opens in new tab)

Last updated 2026-09-08