| 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: demo.playwright.pwc
on:
workflow_dispatch:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
run-tests:
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 pwcThe workflow above is the simplest way to get started. As you scale, using parallelization becomes very important to keep execution time fast.
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.
{% 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.
- argos-example.yml - run Playwright tests in parallel using Currents Orchestration, use Argos CI for visual testing.
