1. Home
  2. Blog
  3. DevOps

DevOps

GitHub Actions Playwright Workflow: Run Tests on Every Pull Request

Set up a GitHub Actions Playwright workflow that runs your end-to-end tests on every pull request, uploads the report and scales with sharding. Copy-paste YAML included.

9 min read
GitHub Actions Playwright workflow that runs tests on every pull request

Key takeaways

  • Use the Playwright CLI in the workflow; the old playwright-github-action is deprecated.
  • The core steps are checkout, setup-node, npm ci, npx playwright install --with-deps and npx playwright test.
  • Upload the HTML report as an artifact, even when tests fail.
  • Split large suites with --shard and merge the blob reports into one report.

Tests that only run on your laptop protect nobody. The moment a teammate opens a pull request, you want the same browser tests to run automatically and block the merge if they fail. A GitHub Actions Playwright workflow does exactly that, and the basic version is about 25 lines of YAML.

This guide builds that workflow in stages: first the minimum that works, then pull request triggers, report uploads, sharding and the fixes for failures that only appear in CI. Everything follows the official Playwright CI introduction.

If you are new to workflows, read our GitHub Actions CI/CD guide first. It explains triggers, jobs and secrets from scratch.

The basic GitHub Actions Playwright workflow

When you run npm init playwright@latest, the installer offers to add this file for you. Save it as .github/workflows/playwright.yml:

name: Playwright Tests
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]
jobs:
  test:
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: lts/*
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test
      - uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30

The action versions above match what the Playwright docs showed when I checked. Action versions move, so confirm the latest in each action’s repository, for example actions/upload-artifact.

Why the extra timeout: the docs example sets no job-level timeout-minutes and suggests globalTimeout in playwright.config.ts so reporters still produce a report when the run is cut short. A job timeout is still a useful safety net; just keep it above your global one.

What each step in the GitHub Actions Playwright file does

Step Purpose
actions/checkout Copies your repository onto the runner
actions/setup-node Installs Node.js (lts/* picks the current long-term release)
npm ci Clean, repeatable install from the lock file
playwright install --with-deps Downloads browsers plus the Linux libraries they need
playwright test Runs the suite; a non-zero exit code fails the job
upload-artifact Saves the HTML report so you can download it

Do not use the archived microsoft/playwright-github-action from older tutorials. The Playwright team recommends the CLI approach shown here.

Make GitHub Actions Playwright run on every pull request

A GitHub Actions Playwright job only protects the branch if it is required, so wire it into branch protection.

The pull_request trigger already starts the job for each PR into main. To make it a real gate, open the repository settings, add a branch protection rule (or ruleset) for main and mark the test job as a required status check. Now a red run blocks the merge button.

Two refinements help on busy repositories. First, cancel outdated runs when someone pushes again:

concurrency:
  group: pw-${{ github.ref }}
  cancel-in-progress: true

Second, skip browser tests when only docs changed:

on:
  pull_request:
    paths-ignore:
      - '**.md'
      - 'docs/**'

A common setup is a small smoke subset on each PR and the full suite nightly. Our smoke testing vs sanity testing guide shows how to tag the quick tests, and the regression testing checklist helps decide what belongs in the nightly run.

Keep the report and traces

Good reports turn a GitHub Actions Playwright failure into a five-minute fix instead of a guessing game.

A failure message in a log is rarely enough. Save the HTML report (already done above) and turn on traces for retried tests in playwright.config.ts:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 2 : undefined,
  reporter: [['html'], ['list']],
  use: { trace: 'on-first-retry' },
});

Download the playwright-report artifact from the run page, open index.html and click a failed test to see the trace with screenshots, network calls and a step timeline. Retries are for diagnosis, not for hiding flakiness: any test that passes only on retry is reported as flaky, so fix it.

Speed up a slow suite with sharding

Sharding is the usual next step for a GitHub Actions Playwright setup once the suite grows.

When the suite passes ten minutes, split it across machines. Playwright supports this with --shard, described in the sharding documentation. Use a matrix job plus the blob reporter, then merge:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with: { node-version: lts/* }
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: npx playwright test --shard=${{ matrix.shard }}/4 --reporter=blob
      - uses: actions/upload-artifact@v4
        if: ${{ !cancelled() }}
        with:
          name: blob-report-${{ matrix.shard }}
          path: blob-report
          retention-days: 1

  merge-reports:
    if: ${{ !cancelled() }}
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with: { node-version: lts/* }
      - run: npm ci
      - uses: actions/download-artifact@v4
        with:
          path: all-blob-reports
          pattern: blob-report-*
          merge-multiple: true
      - run: npx playwright merge-reports --reporter html ./all-blob-reports
      - uses: actions/upload-artifact@v4
        with:
          name: html-report
          path: playwright-report

Four shards roughly quarter the wall-clock time, at the cost of four times the runner minutes. Check the free-minute allowance on your GitHub plan before you shard everything.

When tests pass locally but fail in GitHub Actions

Almost every GitHub Actions Playwright failure that is absent locally comes from one of these causes.

  • Different screen size or fonts. Visual snapshots made on macOS will not match Linux. Generate snapshots in the same environment as CI.
  • Slower machines. Replace fixed sleeps with web-first assertions that wait automatically. See end to end testing best practices.
  • Too many workers. Shared runners have limited CPU. Lower workers if you see random timeouts.
  • Missing browser libraries. Always use --with-deps on a fresh runner.
  • Test data collisions. Parallel tests that share one user or record will interfere with each other.

Secrets and the base URL

Credentials need extra care in a GitHub Actions Playwright pipeline.

Never write passwords in the YAML. Store them under Settings, Secrets and variables, then pass them as environment variables. Keep the target address in config as well, so the same tests run against local and preview environments.

- name: Run Playwright tests
  run: npx playwright test
  env:
    BASE_URL: ${{ vars.STAGING_URL }}
    TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}

In playwright.config.ts read process.env.BASE_URL for use.baseURL. Secrets are not passed to workflows triggered from forked repositories, so tests that need them will not run on fork PRs by default.

Common mistakes

  • Copying an old tutorial that uses the deprecated Playwright action.
  • Skipping npm ci and using npm install, which can change the lock file mid-run.
  • Uploading the report only on success, so failures leave nothing to inspect.
  • Making the full suite a required check when it takes 40 minutes.
  • Pinning no versions anywhere, then wondering why Tuesday’s run behaves differently.

Final thoughts

A reliable GitHub Actions Playwright setup is small: the basic workflow, a required status check, a report you can open and sharding only when the run gets slow. Start with the 25-line file, make it required on pull requests and improve it one problem at a time.

Frequently asked questions

How do I run a GitHub Actions Playwright workflow?

Add a workflow file that checks out the repo, sets up Node, runs npm ci, installs browsers with npx playwright install –with-deps and then runs npx playwright test.

How do I run Playwright tests on every pull request?

Use the pull_request trigger in the workflow, then mark the job as a required status check in branch protection so failing tests block the merge.

Should I still use microsoft/playwright-github-action?

No. It is deprecated, and the Playwright team recommends installing and running tests through the CLI as shown above.

How do I see the Playwright report from GitHub Actions?

Upload the playwright-report folder with actions/upload-artifact, then download it from the workflow run page and open index.html.

How can I make Playwright CI runs faster?

Shard the suite across a matrix with –shard, limit workers on small runners and run only a smoke subset on each pull request.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

LLM Structured Output Explained: Getting Reliable JSON From AI Models

LLM structured output explained with validation we ran in Pydantic: JSON mode and schemas, constrained decoding, the ways model output…

Read article →
DevOps

SSH Keys Explained: How They Work, ssh-keygen, Ed25519 and Safe Habits

SSH keys explained with keys we generated: public vs private keys, ssh-keygen, Ed25519 vs RSA, fingerprints, passphrases, ssh-agent, authorized_keys, config…

Read article →
DevOps

HTTP Caching Explained: Cache-Control, ETag and 304 Responses, With a Live Test

HTTP caching explained with a small server we ran: Cache-Control directives, max-age, no-cache vs no-store, ETag revalidation and 304 responses,…

Read article →
Test Automation

API Contract Testing Explained: Catch Breaking Changes Before They Ship

API contract testing explained with a schema check we ran: what a contract is, consumer-driven contracts, Pact, OpenAPI, which changes…

Read article →
Software Testing

Risk-Based Testing Explained: Score Risks, Build a Matrix and Test What Matters

Risk-based testing explained step by step: identifying risks, scoring likelihood and impact, building a risk matrix, mapping risk to test…

Read article →
Databases & SQL

SQL Constraints Explained: NOT NULL, UNIQUE, CHECK and FOREIGN KEY, Tested

SQL constraints explained with tests we ran: NOT NULL, UNIQUE, CHECK, DEFAULT, PRIMARY and FOREIGN KEY, the NULL loopholes, SQLite's…

Read article →
Databases & SQL

SQL Date Functions Explained: Adding, Comparing and Grouping Dates Without Bugs

SQL date functions explained with queries we ran: adding intervals, month-end surprises, date differences, the BETWEEN trap, grouping by day,…

Read article →
Software Development

Python asyncio Explained: async, await, gather and TaskGroup With Real Timings

Python asyncio explained with code we timed: coroutines, await, gather, TaskGroup, error handling, timeouts, limiting concurrency and the blocking-call mistake…

Read article →
Software Development

Debounce vs Throttle in JavaScript: How They Work, When to Use Each, Tested

Debounce vs throttle in JavaScript explained with timings we measured in Node.js: how each works, simple implementations, leading and trailing…

Read article →
Software Development

Python Context Managers Explained: The with Statement, contextlib and Real Uses

Python context managers explained with code we ran: how with works, __enter__ and __exit__, contextlib.contextmanager, suppress, ExitStack, database transactions and…

Read article →
Artificial Intelligence

LLM Temperature and Top-p Explained: How AI Models Choose Their Next Word

LLM temperature and top-p explained with a simulation we ran: how probabilities are reshaped, what top-p keeps, recommended settings by…

Read article →
DevOps

YAML Explained: Syntax, the Norway Problem and Other Traps We Tested

YAML explained with a parser test: basic syntax, lists and maps, the Norway problem, versions turning into floats, octal zip…

Read article →
DevOps

Cron Jobs Explained: Syntax, Real Schedules and the Mistakes That Break Them

Cron jobs explained with schedules we verified: the five fields, operators, real examples, the day-of-month OR day-of-week trap, environment problems,…

Read article →
Software Testing

Bug Life Cycle in Software Testing: Every Status, Who Owns It and Common Mistakes

The bug life cycle explained: every defect status from New to Closed, who owns each step, rejected, deferred and reopened…

Read article →
Test Automation

Property-Based Testing in Python: Hypothesis Finds the Bugs Your Examples Miss

Property-based testing explained with Hypothesis tests we ran: properties vs examples, strategies, shrinking, the real bugs it found in our…

Read article →
Databases & SQL

SQL Pagination Explained: OFFSET vs Keyset, With a Million-Row Test

SQL pagination explained with a million-row test we ran: LIMIT and OFFSET, why deep pages get slow, keyset (cursor) pagination,…

Read article →
Databases & SQL

SQL EXISTS vs IN: Differences, the NOT IN NULL Trap and Performance

SQL EXISTS vs IN explained with queries we ran: how each works, why NOT IN returns no rows when a…

Read article →
Software Development

Python Logging Explained: Levels, Handlers, Formatters and Mistakes to Avoid

Python logging explained with code we ran: levels, basicConfig quirks, named loggers, handlers and formatters, logger.exception, lazy formatting, duplicate logs…

Read article →
Software Development

JavaScript Map vs Object: Key Differences, Pitfalls and a Benchmark

JavaScript Map vs Object explained with code we ran in Node.js: key types, ordering, the prototype trap, JSON, size, WeakMap…

Read article →
Software Development

Python Type Hints Explained: Annotations, mypy and the Errors It Catches

Python type hints explained with a real mypy run: basic annotations, Optional and unions, TypedDict, Literal, Protocol, generics, Callable, strict…

Read article →
Artificial Intelligence

LLM Tokens Explained: How AI Models Read Text, Count Costs and Fill Context Windows

LLM tokens explained with a tokenizer we ran: how text is split, why counts differ by language and tokenizer, context…

Read article →
DevOps

Semantic Versioning Explained: MAJOR.MINOR.PATCH, Ranges and Release Rules

Semantic versioning explained with code we ran: MAJOR.MINOR.PATCH rules, pre-releases, correct version sorting, caret and tilde ranges, 0.x versions, lockfiles…

Read article →
DevOps

Git Reset vs Revert: How to Undo Commits Safely, With a Tested Example

Git reset vs revert explained with a repository we built: soft, mixed and hard reset, revert commits, reverting merges, recovering…

Read article →
Software Testing

The Test Pyramid Explained: Layers, Ratios and When to Break the Shape

The test pyramid explained: unit, integration and end-to-end layers, sensible ratios, the ice cream cone anti-pattern, the testing trophy and…

Read article →
Test Automation

pytest Fixtures Explained: Scope, yield Teardown, conftest.py and Factories

pytest fixtures explained with a suite we ran: how fixtures work, scopes, yield teardown, conftest.py, factory fixtures, parametrized fixtures, built-ins…

Read article →
Databases & SQL

SQL Upsert Explained: INSERT ON CONFLICT, MERGE and the REPLACE Trap

SQL upsert explained with queries we ran: INSERT ON CONFLICT DO UPDATE and DO NOTHING, the excluded row, conditional updates,…

Read article →
Databases & SQL

SQL LIKE Operator Explained: Wildcards, Case Sensitivity and Performance

The SQL LIKE operator explained with queries we ran: % and _ wildcards, escaping, NOT LIKE and NULL, case sensitivity…

Read article →
Artificial Intelligence

AI Hallucinations Explained: Why Language Models Make Things Up and How to Reduce It

AI hallucinations explained: what they are, why language models produce them, common types, how to reduce them with grounding and…

Read article →
Test Automation

Mocking in Python: unittest.mock, patch and the Mistakes That Make Tests Lie

Mocking in Python with unittest.mock, tested: Mock and return_value, side_effect, patching where a name is used, spec and autospec, mocking…

Read article →
Software Testing

Code Coverage Explained: Line vs Branch Coverage and What 100% Really Means

Code coverage explained with a real coverage.py run: line, branch and condition coverage, reading a report, why 100% coverage can…

Read article →
Artificial Intelligence

What Are AI Agents? How They Work, With a Simple Agent Loop You Can Run

What are AI agents? A plain guide to the agent loop, tools, memory and guardrails, with a small Python loop…

Read article →
Test Automation

TDD vs BDD: Key Differences, One Feature Built Both Ways and When to Use Each

TDD vs BDD explained with one discount feature built both ways: red-green-refactor with code we ran, Given-When-Then scenarios, tools, trade-offs…

Read article →
Software Testing

User Acceptance Testing (UAT): Process, Checklist and Real Examples

User acceptance testing explained: who runs it, how it differs from QA, a seven-step process, a UAT test case template,…

Read article →
Artificial Intelligence

What Are Embeddings? Vectors and Cosine Similarity Explained Simply

What are embeddings? A plain-language guide to vectors, cosine similarity and semantic search, with a small example we ran, common…

Read article →
Test Automation

Flaky Tests: What Causes Them and How to Fix Them for Good

Flaky tests explained with demos we ran: the main causes, how to confirm and diagnose one, proper fixes for timing,…

Read article →
Software Testing

Load Testing vs Stress Testing: Differences, Metrics and k6 Examples

Load testing vs stress testing explained: what each proves, spike and soak tests, the metrics that matter, why averages mislead,…

Read article →