Playwright - GitHub Actions

Running Playwright tests in Parallel in GitHub Actions using Matrix Workflow

Currents collects Playwright test results from GitHub Action CI Runners, together with the generated artifacts (trace files, screenshots, videos) for more efficient troubleshooting and providing insights into the test suite performance:

  • console output

  • screenshots

  • videos

  • traces

Playwright in GitHub Actions

GitHub Actions Matrix and Playwright Sharding speed up you CI pipeline by running tests in parallel - playwright support splitting the tests between multiple CI machines using --shard CLI flag.

Read our CI Optimization guide to discover how to speed up your Playwright test in GitHub Actions.

Example

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.

Re-run only failed tests in 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 Action to simplify the re-runs.

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 Action 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 Action to include the data from the last run.

Step-by-step guide:

Install the @currents/cmd package
Add the currents-dev/playwright-last-failed step

Add a step to your workflow before you run your tests

See the action configuration for details.

A full example

Full examples:

  • rerun-shards-pwc.yml - rerun only the tests that failed in the previous run, using pwc helper command that is included in @currents/playwright package.

  • rerun-shards-reporter.yml - rerun only the tests that failed in the previous run, using reporter explicitly configured in playwright.config.ts

Currents Orchestration

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

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:

Install the @currents/cmd package
Set CURRENTS_API_KEY CI environment variable

Obtain an API key (see API Keys) from Currents Dashboard (in addition to Record Key) and set GitHub Actions Secret

Add the currents-dev/playwright-last-failed step

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

See the action configuration for details on the inputs.

A full example

Example workflow:

  • reruns-or8n.yml - rerun only the tests that failed in the previous orchestrated run.

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?