Skip to main content

Playwright GitHub Actions: Run Your Tests in CI Step by Step

By 12 min read

In this article (25)
  1. The Starter Playwright GitHub Actions Workflow
  2. What Each Step Does
  3. The trigger
  4. The job and the runner
  5. Checkout and Node.js
  6. Install dependencies
  7. Install the browsers
  8. Run the tests
  9. Upload the HTML report
  10. How to Read the Report From an Artifact
  11. Make Your Config CI-Aware
  12. Retries in CI only
  13. Traces on the first retry
  14. One worker, and a global timeout
  15. Playwright Sharding in GitHub Actions
  16. Step 1: use the blob reporter on CI
  17. Step 2: a matrix job that runs the shards
  18. Step 3: merge the reports
  19. Keep Secrets Out of the Repository
  20. How to Talk About This in an Interview
  21. Frequently Asked Questions
  22. 1. "Do I need to install Playwright browsers in every GitHub Actions run?"
  23. 2. "Why does my Playwright HTML report not open after I download it?"
  24. 3. "How many shards should I use for Playwright in GitHub Actions?"
  25. 4. "Should I turn on retries for Playwright tests?"

To run Playwright in GitHub Actions, add one workflow file to .github/workflows that checks out your code, installs Node.js and your npm packages, installs the Playwright browsers, runs npx playwright test, and uploads the HTML report as an artifact. That is the whole Playwright GitHub Actions setup. The rest of this guide explains each step, then shows how to split a slow suite across machines with sharding, how to retry only in CI, and how to keep passwords and tokens out of your repository.

Every YAML key, action version and flag below comes from the current Playwright and GitHub documentation. If you are new to pipelines in general, read CI/CD for QA engineers first, then come back here.

The Starter Playwright GitHub Actions Workflow

You do not need to write this file from nothing. When you run npm init playwright@latest, Playwright can generate a workflow for you. The Playwright CI intro shows the same file. Save it as .github/workflows/playwright.yml:

yaml
name: Playwright Tests
on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
jobs:
  test:
    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@v5
      if: ${{ !cancelled() }}
      with:
        name: playwright-report
        path: playwright-report/
        retention-days: 30

Commit it, push it, and open the Actions tab in your repository. You will see a run start on every push and every pull request to main or master.

What Each Step Does

Reading the file top to bottom is the fastest way to understand it. It is also what an interviewer expects you to do when they paste a workflow and ask "what happens here?"

The trigger

The on block says when the workflow runs. Here it runs on a push to main or master, and on any pull request that targets those branches. That gives you feedback before a change is merged, which is the point of running tests in CI.

The job and the runner

jobs holds one job called test. The line runs-on: ubuntu-latest asks GitHub for a fresh Linux virtual machine. Every run starts clean, so nothing left over from yesterday can make a test pass or fail.

Checkout and Node.js

actions/checkout@v6 copies your repository onto the runner. actions/setup-node@v6 installs Node.js, and node-version: lts/* picks the current long-term support release.

Install dependencies

npm ci installs the exact versions in your package-lock.json. That keeps the Playwright version in CI the same as the one on your laptop.

Install the browsers

npx playwright install --with-deps downloads the browsers Playwright needs and the operating system libraries they depend on. The Playwright CI docs say caching these browser binaries is not recommended. Restoring the cache takes about as long as downloading them, and the Linux system dependencies cannot be cached anyway. So keep this step simple.

Run the tests

npx playwright test runs your whole suite. Playwright runs headless by default, which is what you want on a CI machine with no screen. If a test fails, open the run, expand the "Run Playwright tests" step, and read the error, the expected and received values, and the call log.

Upload the HTML report

The last step uses actions/upload-artifact@v5 to save the playwright-report/ folder for 30 days. The line if: ${{ !cancelled() }} matters. Without a condition, a step only runs when the steps before it passed, so a failing test run would skip the upload. That is exactly when you need the report most.

How to Read the Report From an Artifact

When the run finishes, scroll to the Artifacts section of the run page and download playwright-report. It arrives as a zip file. Extract it, ideally into a folder where Playwright is already installed, and serve it:

bash
npx playwright show-report name-of-my-extracted-playwright-report

Do not double-click the index.html file. The Playwright docs explain that the report needs a web server to load, so opening the file directly will not work. Once it is served, click the trace icon next to a failing test to open the trace viewer and step through every action.

One warning from the Playwright docs is worth repeating to your team. Traces, reports and console logs can contain credentials, tokens or source code. Treat them as sensitive, and only upload them to stores you trust.

Make Your Config CI-Aware

The workflow is only half of the setup. Your playwright.config.ts decides how the tests behave once they are running. GitHub Actions always sets an environment variable called CI to true, so your config can check process.env.CI and behave differently on the runner than on your laptop.

Here is a config that uses the settings from the Playwright configuration docs:

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

export default defineConfig({
  // Fail the build on CI if you accidentally left test.only in the source code.
  forbidOnly: !!process.env.CI,

  // Retry on CI only.
  retries: process.env.CI ? 2 : 0,

  // Opt out of parallel tests on CI.
  workers: process.env.CI ? 1 : undefined,

  // Fail the run after an hour, so that the reporters still produce a report.
  globalTimeout: 60 * 60 * 1000,

  use: {
    // Collect trace when retrying the failed test.
    trace: 'on-first-retry',
  },
});

Retries in CI only

By default, Playwright does not retry failing tests. Setting retries: process.env.CI ? 2 : 0 gives a failing test two more attempts on the runner, and none on your machine. Locally you want the honest failure straight away so you can fix it.

A retry is not a way to hide problems. When a test fails first and then passes on a retry, Playwright marks it as "flaky" in the report instead of "passed". That label is your to-do list. If you see the same test there every week, work through how to fix flaky Playwright tests rather than raising the retry count.

Traces on the first retry

trace: 'on-first-retry' records a trace only when a test is retried. Passing tests cost you nothing, and every flaky or failing test comes with the evidence you need.

One worker, and a global timeout

The Playwright CI docs recommend one worker on CI for stability and reproducibility. If you need more speed, the docs point you to sharding instead, which is the next section.

The docs also say to always set a globalTimeout in CI. Without it, a suite that hangs runs until GitHub kills the job, and you get no report. A GitHub job is cancelled after 360 minutes by default. If you add your own timeout-minutes to the job, keep it comfortably above globalTimeout, so Playwright always stops first and writes its report.

Learning GitHub Actions properly? Read a free lesson from Manual to Automation Mastery, or see the course.

Playwright Sharding in GitHub Actions

When your suite gets slow, sharding splits it across several machines that run at the same time. Playwright does the splitting with one flag. This command runs the first quarter of your tests:

bash
npx playwright test --shard=1/4

For an even split, set fullyParallel: true in your config. The Playwright sharding guide explains that this lets Playwright divide individual tests between shards. Without it, whole files are divided, so one large file can make one shard much slower than the rest.

Step 1: use the blob reporter on CI

Each shard writes its own partial report. Playwright's blob reporter saves those parts so they can be merged later. Add this line to playwright.config.ts:

ts
reporter: process.env.CI ? 'blob' : 'html',

Step 2: a matrix job that runs the shards

GitHub Actions runs one job for every combination in a matrix. This workflow from the Playwright docs starts four jobs, one per shard:

yaml
name: Playwright Tests
on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
jobs:
  playwright-tests:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        shardIndex: [1, 2, 3, 4]
        shardTotal: [4]
    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 --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

    - name: Upload blob report to GitHub Actions Artifacts
      if: ${{ !cancelled() }}
      uses: actions/upload-artifact@v5
      with:
        name: blob-report-${{ matrix.shardIndex }}
        path: blob-report
        retention-days: 1

Notice fail-fast: false. In GitHub Actions, fail-fast defaults to true, which cancels every other job in the matrix as soon as one fails. For tests you want the opposite: let every shard finish, so you see every failure in one run instead of one shard's worth.

Step 3: merge the reports

Add a second job under jobs that waits for the shards, downloads every blob report, and merges them into one HTML report:

yaml
  merge-reports:
    # Merge reports after playwright-tests, even if some shards have failed
    if: ${{ !cancelled() }}
    needs: [playwright-tests]

    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: Download blob reports from GitHub Actions Artifacts
      uses: actions/download-artifact@v5
      with:
        path: all-blob-reports
        pattern: blob-report-*
        merge-multiple: true

    - name: Merge into HTML Report
      run: npx playwright merge-reports --reporter html ./all-blob-reports

    - name: Upload HTML report
      uses: actions/upload-artifact@v5
      with:
        name: html-report--attempt-${{ github.run_attempt }}
        path: playwright-report
        retention-days: 14

needs: [playwright-tests] makes this job wait for the shards. By default, GitHub skips a job when a job it needs has failed. The if: ${{ !cancelled() }} condition overrides that, so you still get a merged report when some tests fail. The blob reports only live for one day, because the merged HTML report is the one you keep.

Keep Secrets Out of the Repository

Real suites often need a test account password or an API token. Never write these into your test files or your workflow. Store them as encrypted secrets in your repository settings, then pass them to the test step as environment variables:

yaml
    - name: Run Playwright tests
      run: npx playwright test
      env:
        TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}

Your test reads the value with process.env.TEST_USER_PASSWORD. Three rules from the GitHub and Playwright docs keep this safe:

  • Prefer environment variables over command-line arguments. The GitHub guide to using secrets warns that command-line processes may be visible to other users.
  • If a secret is not set, the expression returns an empty string. Fail loudly in your setup code when the value is empty, so a missing secret does not look like a broken login page.
  • Workflows triggered by pull requests from forked repositories cannot read your secrets, so steps that need them will not work there. Plan for that if your project accepts outside contributions.

Remember the earlier warning too. A trace records what the page did, which can include a typed password. Keep report artifacts private.

How to Talk About This in an Interview

CI questions come up in almost every automation interview, and a clear walkthrough of this setup is a strong answer. Practise saying it in this order:

  1. "Our tests run on every pull request in GitHub Actions on a clean Ubuntu runner."
  2. "We install with npm ci and npx playwright install --with-deps, so CI matches local versions."
  3. "Retries are on only in CI, with traces on the first retry, and we track tests marked flaky instead of ignoring them."
  4. "We shard across four jobs with fail-fast: false, then merge the blob reports into one HTML report."
  5. "Secrets come from the repository's encrypted secrets as environment variables, never from code."

Each point invites a follow-up, and you now know the reason behind each one. For more practice, work through these GitHub Actions interview questions and the Playwright interview questions. If you want to say the answer out loud before the real thing, the Live Interview Coach in AssertHired runs a QA mock interview that adapts with follow-up questions.

Frequently Asked Questions

1. "Do I need to install Playwright browsers in every GitHub Actions run?"

Yes. Each run starts on a fresh runner, so npx playwright install --with-deps runs every time. The Playwright docs do not recommend caching the browsers, because restoring the cache takes about as long as downloading them and the Linux system dependencies cannot be cached.

2. "Why does my Playwright HTML report not open after I download it?"

The report needs a web server to load. Extract the zip, then run npx playwright show-report followed by the folder name. Opening index.html directly in the browser will not work.

3. "How many shards should I use for Playwright in GitHub Actions?"

Start with the four shards from the official example and measure. Set fullyParallel: true so tests split evenly. Add shards only when each one still takes too long, since every shard installs dependencies and browsers on its own.

4. "Should I turn on retries for Playwright tests?"

Turn them on in CI only, with retries: process.env.CI ? 2 : 0. Locally you want the real failure at once. In CI, a test that passes on retry is marked flaky in the report, which tells you exactly which tests need fixing.

NEWSLETTER  /  QA.PREP

QA interview tips, straight to your inbox.

Join QA engineers getting one short QA lesson every week: interview prep, automation tips, and real hiring insight, plus the occasional AssertHired update. No spam, unsubscribe anytime.