Speed up Playwright tests in GitHub Actions
A Playwright config capturing traces and videos unconditionally pays the recording and upload cost on every run, including the ones that pass and whose artifacts nobody ever opens; setting trace and video to failure-only keeps the same debugging evidence for red runs and removes the cost from green ones.
ci.hygiene.playwright-artifactsstatic · checkable from the repoAI agents open the PR
StarSling agents run this exact audit on your workflows, apply the fix, and open a reviewable PR automatically.
Do this
Playwright's trace and video recorders write to disk while the suite runs and the upload-artifact step then has to compress and transfer whatever they produced. When trace or video is set to "on", that recording and upload happens on every run regardless of outcome, so a suite that passes ninety-nine times out of a hundred still writes and uploads ninety-nine sets of traces and videos that exist only to be deleted by the artifact retention window. on-first-retry and retain-on-failure record only when a test actually needs debugging, and the CI job itself only writes an upload-artifact step conditioned on failure() so passing runs skip the step's own overhead too.
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
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: test-results/Avoid this
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
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.Search the workflow for the upload step:
grep -n 'actions/upload-artifact' -A5 .github/workflows/*.yml- check whether the step has anif: failure()(orif: always()deliberately paired with a failure-only trace config) guarding it; an unconditioned upload step runs after passing jobs too.Search for the browser install step:
grep -n 'playwright install' .github/workflows/*.yml- a barenpx playwright install --with-depswith 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
retriesconfigured above zero; with retries at zero, on-first-retry never fires and a failing test produces no trace at all.A flaky test that fails once and passes on retry still leaves no trace under on-first-retry, because the run's final status is green; if flake investigation matters more than storage cost, retain-on-failure records on every failure including ones later retried away.
if: failure() skips the upload step on a run that was cancelled rather than failed; add if: failure() || cancelled() when artifacts from a cancelled run are also worth keeping.
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.
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. Read the workflow file that runs the suite. For every actions/upload-artifact step that
uploads a Playwright report or test-results directory, add if: failure() unless it
already has an equivalent condition.
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: force a failing test and confirm a trace/video is still
produced and uploaded, then confirm a passing run skips the upload steps.Confirm the change landed
Run the suite with all tests passing and confirm the workflow's upload-artifact steps show as skipped in the run summary, not executed.
Force one test to fail and confirm the run produces a trace (and video, if configured) and that the upload-artifact steps run and attach it.
Compare the job's total duration on a passing run before and after the change; a passing run should no longer include artifact compression and upload time.
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.
Fix this one thing
Copy the prompt above
Hand OPT56 to your coding agent and fix it in your repo today.
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.
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 viewer (opens in new tab)
2Playwright: Test configuration (video, screenshot) (opens in new tab)
Last updated 2026-08-21