Re-run Only Failed Tests

How to setup failed tests re-run on GitHub Actions

When a workflow fails in GitHub Actions you have the option to re-run the failed jobs. However, an additional setup is required for properly configure Playwright for rerunning only the failed tests.

See Re-run Only Failed Tests guide for more details on re-runs.

For GitHub Actions, we provide the Last Failed GitHub Actionarrow-up-right to simplify the re-runs.

circle-info

We recommend you install @currents/cmd as a dev dependency in your package.json, and using npm ci or your package manager's frozen lockfile install method in your GitHub Actions. If you do not the Last Failed GitHub Actionarrow-up-right will instead install and use a global package, which will not respect your package's version lock files, and instead always pull in the latest of @currents/cmdand it's dependencies.

Playwright Sharding

If you're using Reporting in CI for running your tests in parallel, you can use the Last Failed GitHub Actionarrow-up-right to include the data from the last run.

Step-by-step guide:

chevron-rightInstall the @currents/cmd packagehashtag
npm i -D @currents/cmd
chevron-rightAdd the currents-dev/playwright-last-failed stephashtag

Add a step to your workflow before you run your tests

- name: Playwright Last Failed action
  id: last-failed-action
  uses: currents-dev/playwright-last-failed@v1
  with:
    # if you're using a custom CI build id, set "previous-ci-build-id" accordingly 
    # previous-ci-build-id: default is ${{ github.repository }}-${{ github.run_id }}-<%= ${{ github.run_attempt }} - 1 %>
    pw-output-dir: basic/test-results
    matrix-index: ${{ matrix.shard }}
    matrix-total: ${{ strategy.job-total }}

See the action configuration for detailsarrow-up-right.

chevron-rightA full examplehashtag
name: failed-only-reruns

on:
  push:

jobs:
  test-reporter:
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3]
    timeout-minutes: 60
    runs-on: ubuntu-latest
    container: mcr.microsoft.com/playwright:latest
    env:
      CURRENTS_PROJECT_ID: bnsqNa
      CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
      CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
      - run: |
          echo "$GITHUB_WORKSPACE"
          git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - uses: actions/setup-node@v4
        with:
          node-version: "20.x"
      - name: Install dependencies
        run: |
          npm ci
          npx playwright install chrome
      - name: Playwright Last Failed action
        id: last-failed-action
        uses: currents-dev/playwright-last-failed@v1
        with:
          pw-output-dir: basic/test-results
          matrix-index: ${{ matrix.shard }}
          matrix-total: ${{ strategy.job-total }}
      - name: Playwright Tests
        working-directory: ./basic
        run: |
          COMMAND="npx playwright test --config playwright.config.reporter.ts ${{ steps.last-failed-action.outputs.extra-pw-flags }}"
          echo "Running command: $COMMAND"
          $COMMAND
circle-info

Full examples:

Currents Orchestration

If you're using Currents Orchestration for running your Playwright tests you can also fetch the results of from Runs.

circle-info

Currents Orchestration dynamically assigns tests to all the available CI runners, that's why you should select Re-run all jobs when using Currents Orchestration. Read more at Re-run Only Failed Tests guide.

Step-by-step guide:

chevron-rightInstall the @currents/cmd packagehashtag
chevron-rightSet CURRENTS_API_KEY CI environment variablehashtag

Obtain an API key (see Authentication) from Currents Dashboard (in addition to Record Key) and set GitHub Actions Secretarrow-up-right

chevron-rightAdd the currents-dev/playwright-last-failed stephashtag

Add a step that fetches the last-run information prior to running tests

See the action configuration for detailsarrow-up-right on the inputs.

chevron-rightA full examplehashtag

Example workflow:

circle-info

Custom CI Build ID for Reruns

The last-failed-action gets the previous run information using the default CI build ID pattern:

${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}

If you are using a different CI Build ID, specify the previous-ci-build-id configuration property.

Using custom CI build ID for reruns

For example:

Last updated

Was this helpful?