🖤 Black Friday! Use code BLACK and get 50% OFF online courses! 🔥

Check Out the Sale
Rafał Podraza
Back to blog

July 7, 2026

How to Run Playwright Tests in GitHub Actions

Writing automated tests is one thing, but the real value starts when those tests run automatically after every code change. In this article, I will show you how to connect Playwright with GitHub Actions and run end-to-end tests as part of your CI/CD pipeline.

How to Run Playwright Tests in GitHub Actions

Running Playwright tests in GitHub Actions turns local browser checks into an automatic part of your CI/CD process. Instead of waiting for someone to run tests manually, you can check important user journeys whenever code is pushed or a pull request is opened.

In this guide, you will create a GitHub Actions workflow, install Playwright browsers, run tests, and save an HTML report. You will also learn how to start your application in CI, investigate failures with Trace Viewer, and keep the pipeline useful as your test suite grows.


Why run Playwright tests in GitHub Actions?

Local tests are a good starting point, but a green result on one developer’s machine does not guarantee that a later change will work for everyone. A pull request can unintentionally break login, registration, a shopping cart, payment, or a contact form.

GitHub Actions runs your checks in a fresh environment and makes the result visible to the team. A typical process looks like this:

  1. A developer changes the application and pushes the code to GitHub.
  2. A push or pull request triggers the workflow.
  3. The job checks out the repository and installs dependencies and browsers.
  4. Playwright runs the configured tests.
  5. The team reviews the result and downloads the report if necessary.

For example, a checkout smoke test can reveal that a change to a shared component prevents customers from reaching the payment step. Detecting that problem in a pull request is much more useful than discovering it after deployment.


Before you start: Playwright project requirements

This guide assumes you have a repository on GitHub and a Playwright project using Node.js and npm. The workflow below uses Node.js 22 and expects a committed package-lock.json file because it installs dependencies with npm ci.

Get 15% OFF

Sign up for the newsletter and receive a 15% discount code for any course in our shop.

By signing up, you accept the privacy policy.

If you do not yet have a Playwright project, initialize one from your project directory:

npm init playwright@latest

A typical project contains a tests directory, playwright.config.ts, and package.json. Before setting up CI, run the tests locally:

npx playwright test

Fix local failures first, commit your project files and lockfile, and push them to GitHub. If your application needs environment variables, test accounts, or a database, plan how the CI environment will provide them as well.


Create a Playwright workflow in GitHub Actions

1. Add the workflow file

Create the directory .github/workflows in your repository and add a file named playwright.yml. Its full path is .github/workflows/playwright.yml. GitHub reads workflow definitions from this directory.

2. Add the workflow configuration

Add the following lines to playwright.yml, preserving the indentation shown:

name: Playwright Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test:
    name: Run Playwright tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test
      - name: Upload Playwright report
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 7

Commit the file and push it to GitHub. This workflow runs after a push to main and for pull requests targeting main. Open the repository’s Actions tab to inspect each run.

3. Understand each workflow step

  • Triggers: push and pull_request define when the workflow starts. Change main if your repository uses a different target branch.
  • Runner: ubuntu-latest provides the Linux machine on which the job runs.
  • Checkout: actions/checkout@v4 makes the repository files available to the job.
  • Node.js: actions/setup-node@v4 selects Node.js 22. Use a version compatible with your project.
  • Dependencies: npm ci installs the locked dependency tree and is designed for clean, repeatable CI installations.
  • Browsers: npx playwright install --with-deps installs Playwright browsers and required system dependencies.
  • Tests: npx playwright test runs the configured suite.
  • Report: if: always() attempts to upload the report even when an earlier step fails. A report must actually have been generated for an artifact to be available.

Save and review the Playwright HTML report

Configure the HTML reporter in playwright.config.ts so that the workflow has a report to upload. The example below sets reporter to html. The workflow uploads the playwright-report directory as an artifact and retains it for seven days.

After a run finishes, open it in the Actions tab and download the playwright-report artifact. Extract the archive and open its HTML report. Check the failing test, error message, and any available attachments before deciding whether the application, test, or environment caused the failure.

Be careful with sensitive information: reports, screenshots, videos, and traces can contain test data or application content. Use dedicated test accounts and appropriate repository and artifact access controls.


Configure retries, screenshots, video, and Trace Viewer

Playwright Trace Viewer helps you investigate a run step by step. Depending on what was recorded, a trace can show actions, assertions, snapshots, logs, and network activity. This is often more useful than an error message alone.

The following example uses Chromium, retries failed tests twice in CI, records a trace on the first retry, and retains screenshots and video for failures:

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

export default defineConfig({
  testDir: './tests',
  retries: process.env.CI ? 2 : 0,
  reporter: 'html',
  use: {
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});

With on-first-retry, a trace is recorded during the first retry, not the original failed attempt. If retries are disabled, that setting will not produce a retry trace. The HTML report can include links to recorded attachments; verify that they are present in your downloaded artifact.

Retries can reveal intermittent failures, but they should not be used to hide flaky tests. Investigate tests that pass only on retry, and track whether the underlying cause is test isolation, application behavior, or environment instability.


Start the application before running Playwright tests

End-to-end tests often require a running application. Your local server at localhost:3000 will not automatically be running on a fresh GitHub Actions runner. One convenient solution is Playwright’s webServer configuration.

Add the following properties to your existing configuration, adjusting the command and URL to your application:

webServer: {
  command: 'npm run dev',
  url: 'http://127.0.0.1:3000',
  reuseExistingServer: !process.env.CI,
  timeout: 120 * 1000,
},
use: {
  baseURL: 'http://127.0.0.1:3000',
  trace: 'on-first-retry',
},

Playwright starts the command, waits for the configured URL to become available, and then runs the tests. Locally it can reuse an existing server; in CI this example starts a fresh one. If you already configured screenshots or video under use, combine those settings in the same object rather than adding a second use property.

With baseURL set, a test can navigate using a relative path:

import { test, expect } from '@playwright/test';

test('homepage should load', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveTitle(/Example/);
});

Replace the expected title with one that matches your application. If startup also depends on a database, migrations, or environment variables, configure those separately before running the tests.


Run Playwright tests only for pull requests

If you want checks before merging but do not need the same workflow on every push to main, remove the push trigger and keep the pull_request trigger targeting main. Changes pushed to an open pull request can still trigger a new run.

on:
  pull_request:
    branches:
      - main

Choose triggers based on the feedback your team needs. Running a small suite on pull requests and a broader suite after merge or on a schedule is often a practical compromise.


Test Chromium, Firefox, and WebKit

Playwright supports multiple browser engines. Start with Chromium if you need a fast initial suite, then add Firefox and WebKit where cross-browser coverage matters. The following projects can replace the single Chromium project in playwright.config.ts:

projects: [
  { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
  { name: 'webkit', use: { ...devices['Desktop Safari'] } },
],

Make sure the corresponding browsers are installed in CI. Running every scenario in every browser increases execution time, so prioritize critical journeys and adjust coverage to your users and release risk.


Troubleshoot common Playwright CI failures

Browser executable is missing

Check that the workflow runs npx playwright install --with-deps after installing project dependencies. The browser binaries must match the Playwright version used by the project. Review the install step’s logs for errors before rerunning the job.

The application is not available

If navigation to localhost fails, check the server command, port, startup logs, and readiness URL. Use webServer or start the application in a separate workflow step and wait until it is ready. A running process alone does not necessarily mean the application is ready to serve requests.

A test passes locally but fails in CI

Common causes include missing environment variables, local-only data, weak selectors, strict timeouts, environment differences, and dependencies between tests. Inspect the report and trace, then make the test independent and reproducible. Prefer user-facing locators and Playwright’s built-in waiting and assertions over arbitrary delays.

The HTML report is missing

Confirm that the HTML reporter is enabled and that its output directory matches the artifact path. If installation or server startup failed before the reporter produced files, the upload step cannot create a useful report from a nonexistent directory. Check earlier job logs as well as the upload step.

The suite takes too long

Measure which tests and setup steps consume the most time before changing the pipeline. Consider separating smoke tests from full regression, running broader coverage on a schedule, or using Playwright sharding across multiple jobs. When sharding, plan how you will collect and review results from every shard.


Should Playwright tests block a merge?

Stable tests covering important journeys are good candidates for required status checks. Examples include login, registration, shopping cart, payment, form submission, and a basic purchase flow. Configure the relevant required check in your repository’s branch protection or ruleset; simply adding a workflow does not automatically block merges.

Start with a small, reliable suite rather than making a hundred flaky tests mandatory. A check that fails randomly encourages teams to ignore it, while a dependable check builds confidence in the release process.


Separate smoke tests from full regression

A useful CI/CD strategy is to run fast smoke tests on each pull request, execute full regression manually or on a schedule, and add cross-browser coverage before releases. This gives developers quick feedback without abandoning deeper checks.

For example, mark a critical test with @smoke in its name:

test('@smoke user can open homepage', async ({ page }) => {
  await page.goto('/');
  await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
});

Then run only matching tests:

npx playwright test --grep @smoke

Adjust the heading locator to match your application. Keep smoke scenarios focused on the most important user journeys, and include them in the wider regression suite as well.


FAQ: Playwright and GitHub Actions

Do I need to install browsers in every GitHub Actions run?

A fresh GitHub-hosted runner should not be assumed to contain the Playwright browser binaries your project needs. The example installs them during each run. If you later introduce caching or a container, ensure the browser versions still match your Playwright dependency.

Why use npm ci instead of npm install?

npm ci uses the committed lockfile and is intended for clean automated installations. It fails if package.json and the lockfile are out of sync, making dependency inconsistencies easier to detect.

Can I run tests against a deployed environment?

Yes. Point your tests at an appropriate accessible URL instead of starting a local server. Use a dedicated test environment and accounts, and avoid exposing credentials in workflow files or reports.

Does a retry mean the test is reliable?

No. A test that passes only after a retry is still a signal to investigate. Retries can help diagnose intermittent behavior, but stable tests should pass consistently without depending on them.


Key takeaways

Playwright tests become much more valuable when the team can run and review them as part of delivery. Start with a workflow that installs dependencies and browsers, runs a few stable tests, and uploads an HTML report. Then add application startup, traces, smoke tests, cross-browser coverage, or sharding as the project needs them.

The goal is not the most complicated pipeline. It is reliable feedback at the point where your team decides whether a change is ready to merge or release.

To build more hands-on Playwright skills, explore Playwright Practice: 30 Real-World Automation Exercises.

Most popular courses

If this topic is useful to you, these courses are a strong next step.

AI & ChatGPT for QA Engineers
Bestseller
Software Testing

AI & ChatGPT for QA Engineers

4.5(254)
$9.99$19.99
Exam Preparation: ISTQB Test Automation Engineering
Bestseller
Software Testing

Exam Preparation: ISTQB Test Automation Engineering

4.7(242)
$9.99$19.99