Skip to main content
When a CI run fails, re-running the entire job wastes time on tests that have already passed. This workflow runs only the failed tests on subsequent attempts.
InfoExampleYour test suite has 500 E2E tests.
  • A full run takes 1 hour
  • 50 tests fail and take about 6 minutes to run
Re-running the entire suite means executing 450 passing tests again. With this approach, only the 50 failed tests are re-run.Result: You save approximately 54 minutes per re-run.Note: Pricing is based on GitHub’s official Actions runner pricingfor GitHub-hosted runners:
  • Linux (2-core): $0.006 per minute
  • Windows (2-core): $0.010 per minute
  • macOS: $0.062 per minute
This workflow covers sharded execution, GitHub Actions reruns, failed-tests-only reruns, and full-suite fallback when no metadata exists.

Quick Reference

How it works

Two CLI commands power this workflow:
  • npx tdpw cache stores failed test metadata after a run
  • npx tdpw last-failed returns Playwright arguments for the last failed tests
The workflow detects re-runs using github.run_attempt:
NotePlaywright compatibility: Since @playwright/test@1.50+, Playwright has native --last-failed support. TestDino extends this with cross-runner caching, shard awareness, and workflow-level persistence.

Quick start

Add this logic to your Playwright step:
The cache step runs with the if: always() condition, so failures are recorded even when tests fail.
TipNeed to set up your API token? See Generate API Keys for instructions.

How to re-run failed tests in GitHub Actions?

1

Open the failed job

In the GitHub Actions run, find the failed job for Playwright:
  1. Go to your GitHub repository’s Actions tab.
  2. Select the failed workflow run.
  3. Under Jobs, open the job where Playwright tests get executed & fail.
NoteThis is the main job that executes Playwright and sharding.
Step 1: Open failed job
2

Check the run attempt

Inside the job, open the Playwright execution step. In the logs, you can see:
  • GitHub run attempt: <number>
  • Re-run detection output Step 2: Check run attempt
3

Identify the failed tests

Scroll to the end of the Playwright output. GitHub Actions show:
  • Total failed test count
  • Failed test titles Step 3: Identify failed tests
4

Confirm caching

Open the Cache failed test metadata step. Look for:
This confirms TestDino stored the failure metadata.Step 4: Confirm caching
5

Confirm Re-run

Re-run the failed pipeline and confirm the execution of only the last failed tests.
  • The workflow detects run_attempt > 1
  • tdpw last-failed retrieves the failed tests
  • Only those tests are executed Step 5: Confirm re-run part 1 Step 5: Confirm re-run part 2
First run: 12 tests across 3 shards. Two shards fail.Re-run comparison:
Re-runs all tests in failed shards, including tests that already passed.

Full workflow

For a complete workflow with sharding and report merging, see the example repository.
File name: .github/workflows/playwright.ymlRepository: github.com/testdino-hq/playwright-sample-tests-javascript

How the workflow logic works

The workflow uses a conditional check based on github.run_attempt:
  • On the first attempt (run_attempt == 1), the full shard is executed.
  • On subsequent attempts, the workflow attempts to re-run only previously failed tests.
The tdpw last-failed command outputs test filters formatted for Playwright:
These flags can be passed directly to npx playwright test.
The command uses eval to handle quoted arguments in the test filter:
This keeps the -g "pattern" quoting intact when passed to Playwright.

Edge cases

If a job fails during dependency installation or setup, no test metadata exists.On re-run:
  1. tdpw last-failed returns nothing
  2. The workflow detects the empty result
  3. The job runs the full shard
No manual action required. The workflow handles this case automatically:
And then, it will run the normal execution:
Playwright’s --max-failures option stops test execution after N failures. For example:
Playwright stops after 2 failures. Tests that did not run are not recorded.On re-run, only the failed tests execute. Skipped tests are not included as of now.

CI Optimization Overview

CI optimization strategies for Playwright

GitHub Actions

Set up Playwright tests in GitHub Actions

GitHub Status Checks

Configure PR status checks

Flaky Tests

Detect and fix flaky tests