Quick Start

Running Playwright tests in Parallel in GitHub Actions using Matrix Workflow

Quick Start

The example workflow file below shows how to run Playwright tests in GitHub actions.

name: demo.playwright.pwc
on:
  workflow_dispatch:
  pull_request:
    branches: [main]
  push:
    branches: [main]
jobs:
    name: "Playwright Tests"
    timeout-minutes: 60
    runs-on: ubuntu-22.04
    container: mcr.microsoft.com/playwright:v1.49.0-jammy

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      # https://github.com/actions/runner-images/issues/6775
      - 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: | # Add more browsers if needed
          npm ci
          npx playwright install chrome

      - name: Playwright Tests
        continue-on-error: false
        env:
          CURRENTS_PROJECT_ID: bnsqNa # Update to your Project ID
          CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
        run: |
          npx pwc

The workflow above is the simplest way to get started. As you scale, using parallelization becomes very important to keep execution time fast.

Parallelization

By using GitHub Actions matrix execution strategy, you can create multiple containers that will run your Playwright tests in parallel.

Each container will receive a unique set of tests to run so that your tests will run faster and you can receive faster feedback from your browser test suite.

Tests Parallelization with Github Actions

You can achieve that through Playwright Sharding. Playwright supports splitting the tests between multiple CI machines using --shard CLI flag. Below you can find examples on how to setup sharding, and orchestration.

Looking for more ways to speed up CI? Read our CI Optimization page.

Examples

The example repository showcases running Playwright tests in GitHub Actions. We've included several config files to exemplify the workflows:

  • test-basic-pwc.yml - run Playwright tests in parallel using 3 shards of GitHub Actions Matrix and pwc command.

  • test-basic-reporter.yml - run Playwright tests in parallel run using 3 shards of GitHub Actions Matrix and configuring Currents Reporter in playwright.config.ts.

  • test-or8n.yml - run Playwright tests in parallel Playwright using Orchestration Setup and GitHub Actions Matrix. Currents Orchestration speeds up CI runs by up to 40% (compared to native sharding) by optimally balancing tests between the available machines.

  • argos-example.yml - run Playwright tests in parallel using Currents Orchestration, use Argos CI for visual testing.

Last updated

Was this helpful?