| description | Running Playwright tests in parallel on Buildkite with Currents |
|---|
{% hint style="info" %} TL;DR Check out the example repository and the public Buildkite pipeline:
- https://github.com/currents-dev/currents-examples/tree/main/playwright/ci/buildkite
- https://buildkite.com/andrew-goldis/currents-buildkite {% endhint %}
Run Playwright tests in parallel on Buildkite using the native Playwright Sharding to split tests between multiple containers. Parallelizing tests helps decrease overall run duration.
Currents collects results from distributed parallel Buildkite builds for efficient troubleshooting. Each container receives a unique set of tests to run, providing faster feedback from your test suite.
- Create an organization at https://app.currents.dev
- Create a new project
- Obtain
CURRENTS_RECORD_KEYrecord-key.md andCURRENTS_PROJECT_ID - Store
CURRENTS_RECORD_KEYas a pipeline-level secret in your Buildkite dashboard or via the Buildkite Secrets plugin
Buildkite provides BUILDKITE_PARALLEL_JOB (0-indexed) and BUILDKITE_PARALLEL_JOB_COUNT environment variables for parallel jobs. Since Playwright shards are 1-indexed, compute the shard index as BUILDKITE_PARALLEL_JOB + 1:
{% code overflow="wrap" %}
npx playwright test --shard=$((BUILDKITE_PARALLEL_JOB + 1))/$BUILDKITE_PARALLEL_JOB_COUNT{% endcode %}
Configure the Currents reporter in your playwright.config.ts:
{% code title="playwright.config.ts" overflow="wrap" %}
import { currentsReporter } from "@currents/playwright";
import { defineConfig, devices } from "@playwright/test";
export default defineConfig({
reporter: [currentsReporter()],
// ... other config
});{% endcode %}
Create a currents.config.ts file:
{% code title="currents.config.ts" %}
import { CurrentsConfig } from "@currents/playwright";
const currentsConfig: CurrentsConfig = {
projectId: process.env.CURRENTS_PROJECT_ID ?? "your-project-id",
recordKey: process.env.CURRENTS_RECORD_KEY ?? "",
};
export default currentsConfig;{% endcode %}
steps:
- label: ":playwright: Playwright Tests"
command: |
npm ci
npx playwright install --with-deps
npx playwright test --shard=$((BUILDKITE_PARALLEL_JOB + 1))/$BUILDKITE_PARALLEL_JOB_COUNT
parallelism: 3
plugins:
- docker#v5.11.0:
image: "space.vars.PW_IMAGE_ROUTE + ":" + space.vars.LATEST_PW_IMAGE_VERSION"
env:
CURRENTS_PROJECT_ID: "bnsqNa"
CURRENTS_RECORD_KEY: "${CURRENTS_RECORD_KEY}"
This pipeline:
- Runs 3 parallel containers using Buildkite's
parallelismfeature - Uses the official Microsoft Playwright Docker image
- Splits tests using Playwright's native sharding with Buildkite environment variables
- Reports results to Currents via the Playwright Reporter
| Variable | Description |
|---|---|
CURRENTS_PROJECT_ID |
Your Currents project ID |
CURRENTS_RECORD_KEY |
Your Currents record key (store as secret) |
BUILDKITE_PARALLEL_JOB |
Current job index (0-indexed, provided by Buildkite) |
BUILDKITE_PARALLEL_JOB_COUNT |
Total number of parallel jobs (provided by Buildkite) |
{% hint style="info" %} Looking for more ways to speed up CI? Read our ci-optimization guide. {% endhint %}