| description | Running Playwright tests in Parallel in GitHub Actions using Matrix Workflow |
|---|
{% hint style="info" %} Check out the example repository https://github.com/currents-dev/currents-examples {% endhint %}
The example workflow file below shows how to run Playwright tests in GitHub actions.
name: Run Playwright Tests
on:
pull_request:
branches: [main]
jobs:
run-tests:
name: "Playwright Tests"
timeout-minutes: 60
runs-on: ubuntu-22.04
container: space.vars.PW_IMAGE_ROUTE + ":" + space.vars.LATEST_PW_IMAGE_VERSION
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: "24.x"
- name: Install dependencies
run: npm ci
- name: Playwright Tests
continue-on-error: false
env:
CURRENTS_PROJECT_ID: ${{ vars.CURRENTS_PROJECT_ID }}
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
run: npx playwright test
The workflow above is the simplest way to get started. As the test suite grows, parallelization helps keep execution time fast.
The GitHub Actions matrix execution strategy can create multiple containers that run Playwright tests in parallel.
Each container receives a unique set of tests. This makes the browser test suite finish faster and gives feedback sooner.
Tests Parallelization with Github Actions
This can be done with Playwright Sharding. Playwright can split tests between multiple CI machines using the --shard CLI flag. The examples below show how to set up sharding and orchestration.
{% hint style="info" %} Looking for more ways to speed up CI? Read our ci-optimization page. {% endhint %}
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
pwccommand. - 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 playwright-orchestration.md 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.
- reruns-or8n.yml - Orchestration failed-only reruns.
- argos-example.yml - run Playwright tests in parallel using Currents Orchestration, use Argos CI for visual testing.
