Skip to main content
Optimize Playwright test execution in GitHub Actions by caching test results and running only failed tests on subsequent runs.
Playwright @playwright/[email protected]+ includes native --last-failed support. TestDino extends this with cross-runner caching, shard awareness, and workflow-level persistence.

How It Works

  1. Run the full suite. npx playwright test executes all tests.
  2. Cache results. npx tdpw cache reads Playwright’s report and stores pass/fail metadata in TestDino (branch/commit aware, shard aware).
  3. Rerun failures. npx tdpw last-failed returns the exact tests that failed last time. Pass that list to Playwright to run only those tests.
TestDino caching survives new runners, works across shards and jobs, and can be triggered from separate workflows.

Requirements

  • Playwright installed and working in CI
  • TestDino CLI (tdpw) available via npx
  • TestDino API token stored as a GitHub secret (e.g., TESTDINO_TOKEN)
  • TestDino GitHub App for automated uploads/comments (optional but recommended)

Sample GitHub Actions Workflow

1. Full run & cache (playwright-tests.yml)

Runs on push; always caches results immediately after tests. This workflow runs the entire test suite and records the results to establish a baseline.
.github/workflows/test.yml
name: Playwright Tests  
on:  
  push:  
  workflow_dispatch:

jobs:  
  test:  
    runs-on: ubuntu-latest  
    container: mcr.microsoft.com/playwright:latest  
    env:  
      TESTDINO_TOKEN: ${{ secrets.TESTDINO_TOKEN }}  
    steps:  
      - uses: actions/checkout@v4  
      - uses: actions/setup-node@v4  
        with: { node-version: '22.x' }

      - name: Install deps  
        run: |  
          npm ci  
          npx playwright install --with-deps

      - name: Run all tests  
        run: npx playwright test

      - name: Cache test metadata (always)  
        if: always()  
        run: npx tdpw cache --token="${{ secrets.TESTDINO_TOKEN }}"
Place tdpw cache immediately after npx playwright test, guarded by if: always().

2. Rerun failed only (rerun-failed-tests.yml)

Triggered manually; fetches failures, then runs only those tests. This workflow executes only the tests that failed during the main run.
.github/workflows/test.yml
name: failed-only-reruns  
on:  
  workflow_dispatch:

jobs:  
  rerun:  
    runs-on: ubuntu-latest  
    container: mcr.microsoft.com/playwright:latest  
    env:  
      TESTDINO_TOKEN: ${{ secrets.TESTDINO_TOKEN }}  
    steps:  
      - uses: actions/checkout@v4  
      - uses: actions/setup-node@v4  
        with: { node-version: '22.x' }

      - name: Install deps  
        run: |  
          npm ci  
          npx playwright install --with-deps

      - name: Get failed tests from cache
        id: failed_tests
        run: |
          npx tdpw last-failed --token="${{ secrets.TESTDINO_TOKEN }}" > failed.txt
          echo "args=$(cat failed.txt)" >> $GITHUB_OUTPUT

      - name: Run only failed tests
        run: npx playwright test ${{ steps.failed_tests.outputs.args }}

      - name: Cache rerun metadata (always)  
        if: always()  
        run: npx tdpw cache --token="${{ secrets.TESTDINO_TOKEN }}"
Call tdpw last-failed before Playwright, then pass its output to npx playwright test.

Example Scenario

A pull request triggers a full CI run with 50 tests, taking 10 minutes. 47 tests pass, but 3 fail in login.spec.ts, cart.spec.ts, and checkout.spec.ts due to a temporary network issue. Instead of running all 50 tests again, trigger a targeted rerun. The second run executes only those 3 failed tests, completing in under a minute and confirming the issue is resolved.

General Rules

npx tdpw cache --token="$TESTDINO_TOKEN"
Saves pass/fail metadata to TestDino.
npx tdpw last-failed --token="$TESTDINO_TOKEN"
Returns the tests that failed last time.
Pass --token with each command or set TESTDINO_TOKEN as an environment variable.
npx tdpw cache --branch="main" --commit="$GITHUB_SHA" --token="$TESTDINO_TOKEN"
The command returns output formatted for direct use with Playwright:
filename1.spec.ts filename2.spec.ts -g "Test Title 1|Test Title 2"
Pass it directly to npx playwright test for selective reruns.
Continue uploading Playwright reports alongside caching for screenshots, videos, and traces.

Two-Part Workflow

The workflow operates in two stages:
  1. Run & Save: The playwright-tests.yml workflow runs on every code push. It executes all tests to establish a quality baseline and uses tdpw cache to save failures to TestDino.
  2. Fetch & Rerun: If the main run has failures, manually trigger the rerun-failed-tests.yml workflow. It retrieves what failed previously and runs only those tests for a quick verification.
This provides a fast “run everything → cache → rerun failures” loop for GitHub Actions.