Skip to content

Latest commit

 

History

History
101 lines (76 loc) · 3.98 KB

File metadata and controls

101 lines (76 loc) · 3.98 KB
description Running Playwright tests in parallel on Buildkite with Currents

Buildkite

{% hint style="info" %} TL;DR Check out the example repository and the public Buildkite pipeline:

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.

Setup

Sharding

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 %}

Configuration

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 %}

Example Pipeline

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 parallelism feature
  • 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

Environment Variables

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 %}