View as Markdown

Playwright Integration with Mergify

Report your test results from Playwright to Mergify


This guide explains how to integrate Playwright with Test Engine using the @mergifyio/playwright reporter. Once installed, test results are automatically uploaded to Test Engine without any extra workflow changes.

  • Node.js 22 or later in the job that runs the tests. Older versions are not supported: npm and pnpm only warn at install, Yarn 1 refuses.

  • @playwright/test 1.56 or later.

Install the @mergifyio/playwright package alongside @playwright/test to automatically upload your test results to Test Engine.

Use the package manager version your project pins (packageManager in package.json, mise.toml, .tool-versions), and check that the lockfile diff only adds the new packages: another version rewrites unrelated entries (older npm releases, for example, drop the libc fields of other packages; npx npm@latest install … avoids it).

Terminal windowbash
npm install --save-dev @mergifyio/playwright
Terminal windowbash
yarn add --dev @mergifyio/playwright
Terminal windowbash
pnpm add --save-dev @mergifyio/playwright

Setting up the reporter takes two steps, and both are required: the first uploads the results, the second applies quarantine.

Wrap your playwright.config.ts with withMergify:

typescript
import { defineConfig } from '@playwright/test';
import { withMergify } from '@mergifyio/playwright';
export default withMergify(
defineConfig({
// ... your existing configuration
})
);

withMergify adds the Mergify reporter while preserving any reporters, globalSetup, and globalTeardown you already have configured.

With a CommonJS playwright.config.js, require it:

javascript
const { defineConfig } = require('@playwright/test');
const { withMergify } = require('@mergifyio/playwright');
module.exports = withMergify(
defineConfig({
// ... your existing configuration
})
);

Import test and expect from Mergify

Section titled Import test and expect from Mergify

In every test file, and in every fixture file that extends test, import test and expect from @mergifyio/playwright instead of @playwright/test. Type-only imports, such as type Page, can stay on @playwright/test:

typescript
import { test, expect } from '@mergifyio/playwright';
test('logs in', async ({ page }) => {
// ...
});

This import enables test quarantine: when a quarantined test fails, its outcome is reported as passing so it doesn’t block your pipeline.

The plugin uploads results only when the CI environment variable is set, or when MERGIFY_CI_ENABLE is on. GitHub Actions, CircleCI and Buildkite set CI for you. Jenkins does not: set CI=true, or MERGIFY_CI_ENABLE=true, in the stage that runs your tests. If your tests behave differently when CI is set (some test suites skip or add tests on CI), set MERGIFY_CI_ENABLE=true instead of CI, so the tests that run stay the same.

CI counts as set unless it is empty or a false value (false, no, off, 0, f or n), so true, 1 and a CI system’s name (Woodpecker sets CI to woodpecker) all count. MERGIFY_CI_ENABLE is stricter: only true, yes, on, 1, t or y turn it on. Case does not matter for either.

Without a credential, the plugin uploads nothing and your tests run as usual, so pull requests from forks, which get neither an ID token nor secrets, report nothing and need no guard in the workflow.

Every test is identified by its name and the name of the CI job that ran it. By default the job name is the job’s identifier in your CI:

CI Default job name
GitHub Actions the job id (GITHUB_JOB), recorded with the workflow name (GITHUB_WORKFLOW)
CircleCI CIRCLE_JOB, the expanded job name of each matrix leg
Buildkite the step label (BUILDKITE_LABEL)
Jenkins JOB_NAME, also used as the pipeline name, except in a multibranch pipeline (below)

Set MERGIFY_TEST_JOB_NAME when that default is not one stable name per set of tests:

  • GitHub Actions matrix: every leg shares one job id. Set it per leg from the matrix values, for example MERGIFY_TEST_JOB_NAME: test (${{ matrix.python-version }}, ${{ matrix.os }}).

  • Two test runs in one job: set a distinct name on each step.

  • Reusable workflows: a called workflow reports under the caller’s workflow name, so two called workflows whose jobs share an id (often test) collide. Set a distinct name in each.

  • Shards of one test suite are the same tests split across machines: give all shards the same name. Never put a shard index in it.

In a Jenkins multibranch pipeline, every branch and every pull request of the project reports its tests under the same pipeline name and job name: the multibranch project (my-repo, not my-repo/PR-123). MERGIFY_TEST_JOB_NAME replaces the job name but never the pipeline name, so it cannot file the tests of two Jenkins pipelines together. Inside a container, pass BRANCH_NAME through as listed below, or the tests are filed under JOB_NAME.

Tests inside tox, Docker or Docker Compose

Section titled Tests inside tox, Docker or Docker Compose

tox, docker run and Docker Compose start the tests in an environment that does not inherit the CI job’s variables. Pass through CI, MERGIFY_TEST_JOB_NAME if you set it, the credential, and every variable the plugin reads to identify the run. On GitHub Actions the credential is ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN, which GitHub sets in a job granted id-token: write; with a key, it is MERGIFY_TOKEN. tox’s pass_env accepts globs (GITHUB_*); Docker Compose, docker run -e and the Buildkite Docker Compose plugin need each name:

GitHub Actions: GITHUB_ACTIONS GITHUB_BASE_REF GITHUB_EVENT_NAME GITHUB_EVENT_PATH
GITHUB_HEAD_REF GITHUB_JOB GITHUB_REF_NAME GITHUB_REF_TYPE GITHUB_REPOSITORY
GITHUB_REPOSITORY_ID GITHUB_RUN_ATTEMPT GITHUB_RUN_ID GITHUB_SERVER_URL
GITHUB_SHA GITHUB_WORKFLOW RUNNER_NAME
CircleCI: CIRCLECI CIRCLE_BRANCH CIRCLE_BUILD_URL CIRCLE_JOB
CIRCLE_REPOSITORY_URL CIRCLE_SHA1 CIRCLE_WORKFLOW_ID
Buildkite: BUILDKITE BUILDKITE_AGENT_NAME BUILDKITE_BRANCH BUILDKITE_BUILD_ID
BUILDKITE_BUILD_URL BUILDKITE_COMMIT BUILDKITE_LABEL BUILDKITE_PIPELINE_SLUG
BUILDKITE_PULL_REQUEST BUILDKITE_PULL_REQUEST_BASE_BRANCH BUILDKITE_REPO
BUILDKITE_RETRY_COUNT BUILDKITE_STEP_KEY
Jenkins: JENKINS_URL BUILD_ID BUILD_URL JOB_NAME BRANCH_NAME NODE_NAME GIT_URL
GIT_BRANCH GIT_COMMIT CHANGE_ID CHANGE_TARGET CHANGE_BRANCH CHANGE_FORK
TAG_NAME

Pass them by name, never by writing a value into a file. In a container on GitHub Actions, also mount the file GITHUB_EVENT_PATH points to, at the same path: without it the run is recorded against the merge commit instead of the pull request’s head commit.

With an application key, zizmor can report secrets-outside-env on the MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }} line, depending on its version and persona. Run the repository’s own zizmor configuration on the changed workflow, and if it reports the finding, follow the convention the repository already uses for it: a deployment environment on the job, or an inline # zizmor: ignore[secrets-outside-env] comment.

The step that runs your tests needs nothing Mergify-specific:

yaml
- name: Run Tests 🧪
run: npx playwright test

Let your CI reach Mergify Preview

Section titled Let your CI reach Mergify

Grant id-token: write to the job, or to the whole workflow. The job then trades its GitHub-signed ID token for a Mergify token, and no MERGIFY_TOKEN is stored:

yaml
permissions:
id-token: write # lets the job ask GitHub for an ID token
contents: read # actions/checkout needs it

A permissions block sets every permission it does not list to none: list the ones your other steps need too.

Mergify refuses the ID token until a trust policy of your organization matches the job. A GitHub organization Owner or a CI Admin writes one under Settings → Security & Access → CI Authentication → Trust Policies on the dashboard. OIDC Authentication covers trust policies, pull requests from forks and refused exchanges. If your workflows store MERGIFY_TOKEN today, move them off it.

Other CIs authenticate with a ci application key, and so do the GitHub Actions jobs OIDC leaves out: runs for pull requests from forks when your organization sends them secrets, and jobs that send scopes from the base branch (pull_request_target, workflow_run, issue_comment). Store the key as the MERGIFY_TOKEN repository secret and set it on the job:

yaml
env:
MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}

A MERGIFY_TOKEN that is set wins over the ID token. For pull requests from forks, set it on those runs only and drop the fork condition from the upload step, as Jobs that keep a key shows. Store the key in your Dependabot secrets too, since runs for Dependabot pull requests read only those.

Set MERGIFY_TOKEN to a ci application key in the environment of the agents running your tests. The step itself then needs no Mergify-specific configuration:

yaml
steps:
- label: "Run Tests 🧪"
command: npx playwright test

The reporter automatically collects your test results and sends them to Test Engine.

The test you import from @mergifyio/playwright applies test quarantine inside the Playwright run. When a quarantined test ends in any failing status, a timeout included, that test sets the expected status to the outcome, so Playwright counts the result as expected and the result does not change Playwright’s exit code. The exit code of your test step already accounts for quarantine, so the step needs nothing more:

  • Do not add continue-on-error: true. The recipes that upload a JUnit report with the mergifyio/gha-mergify-ci action need it because the action decides the job’s result after the tests. Here nothing does, so it would let every real failure through.

  • There is no step id to set and no test_step_outcome to pass: both belong to that action, which this setup does not use.

A crash cannot pass for a green run either. If Playwright dies mid-run, it exits non-zero and the step fails. The reporter uploads results when the run ends, so a process killed outright before then, such as by the out-of-memory killer, sends nothing to Test Engine.

If the global setup that withMergify adds cannot fetch the quarantine list, the run quarantines nothing, and a quarantined test that fails makes the step fail as usual.

Multi-project (cross-browser) runs

Section titled Multi-project (cross-browser) runs

If your playwright.config.ts defines multiple projects, such as one per browser (chromium, firefox, webkit), the same test runs once per project. A test is identified by its name within the job that ran it, and by default the reporter leaves the project out of that name, so every project’s copy of a test shares one identity and is treated as a single test. A test that passes on chromium but fails on webkit then looks flaky instead of consistently broken on one browser.

To keep each project’s tests separate, set MERGIFY_PLAYWRIGHT_INCLUDE_PROJECT_IN_TEST_NAME to true. The reporter then prefixes each test name with its project, for example [chromium] > login.spec.ts > logs in, so Test Engine tracks flakiness and quarantine per project:

yaml
env:
MERGIFY_PLAYWRIGHT_INCLUDE_PROJECT_IN_TEST_NAME: "true"

This option is opt-in (off by default) to preserve the history of tests that already report without a project prefix.

The reporter uploads each run’s results under your CI job’s name. On GitHub Actions, that name is the job’s identifier (GITHUB_JOB, recorded with the workflow name), which every leg of a matrix shares. The job name is part of a test’s identity in Test Engine, so when the legs run the same tests in different environments, their results merge into one test.

Set MERGIFY_TEST_JOB_NAME on each leg and include the matrix value, so each leg reports under its own name:

yaml
jobs:
e2e:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: read
steps:
# ...
- name: Run Tests 🧪
env:
MERGIFY_TEST_JOB_NAME: e2e (${{ matrix.os }})
run: npx playwright test

Legs that each run one --shard of the suite run different tests, so they can share a name. Leave the shard index out of MERGIFY_TEST_JOB_NAME: adding or removing tests can move a test to another shard, and a name per shard would split that test’s history. When you shard within an environment matrix, name each leg after its environment only, as above.

Setting MERGIFY_TEST_JOB_NAME on a job that already reports changes its name, so its tests start a new history in Test Engine.

Verify and review in Test Engine

Section titled Verify and review in Test Engine

After pushing these changes, your next CI run reports its Playwright results automatically.

You can then review your test results, including any failures or flaky tests, directly in the Test Engine dashboard.

VariablePurpose
MERGIFY_API_URL
defaulthttps://api.mergify.com

Base URL of the Mergify API. An API URL given on the command line or in a reporter's configuration takes precedence.

MERGIFY_CI_DEBUG
defaultfalse

Set to true to upload nothing and print the session verdict and the spans instead of sending them.

MERGIFY_CI_ENABLE
defaultfalse

Set to true to turn the reporter on outside CI. In CI, which the CI variable signals, it is on anyway.

MERGIFY_FAIL_FIRST_ENABLE
defaulttrue

Set to false to stop this job asking Mergify whether it is a merge-queue bisection step, and so never run first the tests it failed in the step above. On by default, and asked only in a build of a merge-queue batch: only a recognised no (false, no, off, 0) turns it off.

MERGIFY_PLAYWRIGHT_INCLUDE_PROJECT_IN_TEST_NAME
defaultfalse

Set to true to prefix each test's name with its Playwright project, so Mergify tracks the test separately in each project.

MERGIFY_TEST_JOB_NAME

Name the job's test results are reported under, instead of the CI job's own name. Set one per environment, never per shard: a name per shard splits a test's history.

MERGIFY_TEST_RETRY_ENABLE
defaulttrue

Set to false to have this job retry no failing test, whatever the repository's test retry configuration. On by default, and test retry only retries on a push to the default branch of a repository that configured it: only a recognised no (false, no, off, 0) turns it off.

MERGIFY_TOKEN

The Mergify credential: an application key in CI. Without it the test reporters upload nothing. A mergify command takes it when --token is not given, over the credential mergify auth login stored, and mergify auth tells when it does. The mergify stack commands send it to GitHub as their GitHub token, ahead of GITHUB_TOKEN, unless it holds a Mergify user token (mut_…).

MERGIFY_TRACEPARENT

W3C traceparent of a trace the job already started: the test session's spans join that trace instead of starting their own. A malformed value is ignored.

MERGIFY_TEST_SELECTION_ENABLE
defaulttrue

Deprecated name of MERGIFY_FAIL_FIRST_ENABLE, read while that one is unset or empty.

PLAYWRIGHT_MERGIFY_ENABLE
defaultfalse

Deprecated name of MERGIFY_CI_ENABLE, read while that one is unset or empty.

PLAYWRIGHT_MERGIFY_INCLUDE_PROJECT_IN_TEST_NAME
defaultfalse

Deprecated name of MERGIFY_PLAYWRIGHT_INCLUDE_PROJECT_IN_TEST_NAME, read while that one is unset or empty.

To check the setup without uploading anything, run your tests with MERGIFY_CI_ENABLE=true MERGIFY_CI_DEBUG=true: the reporter prints the spans it would send.

Was this page helpful?