Playwright

Playwright is a popular end-to-end testing framework for web applications.

Namespace provides high-performance caching for Playwright test runs. By using Cache Volumes, you can cache Playwright's browser binaries and system dependencies across workflow runs, significantly reducing test setup time.

Making full use of the CPUs on our high-performance Compute Platform reduces test times by running tests faster and in parallel.

Getting started

Enable caching on your runner profile

Go to your runner profile configuration and enable caching.

runner profile cache configuration

Add the cache action to your workflow

Use namespacelabs/nscloud-cache-action to cache Playwright browsers and apt packages:

- name: Set up cache
  uses: namespacelabs/nscloud-cache-action@v1
  with:
    cache: |
      playwright
      apt

The playwright cache mode stores downloaded browsers, and apt caches system packages so that playwright install --with-deps runs faster on subsequent runs.

Cache npm dependencies

In addition to Playwright browsers, you can also cache your package manager's dependencies:

For npm, add the ~/.npm directory to the cache action'spath:

- name: Set up cache
  uses: namespacelabs/nscloud-cache-action@v1
  with:
    cache: |
      playwright
      apt
    path: |
      ~/.npm

Install and run Playwright as usual

After setting up the cache, install dependencies and run Playwright as you normally would:

- name: Install dependencies
  run: npm ci
 
- name: Install Playwright browsers
  run: npx playwright install --with-deps
 
- name: Run Playwright tests
  run: npx playwright test

What gets cached

CacheWhat's cached
PlaywrightBrowser binaries downloaded by Playwright (Chromium, Firefox, WebKit)
APTSystem packages installed via apt, including browser dependencies
npm / pnpm / yarnPackage manager cache for faster dependency installation

See the nscloud-cache-action documentation for all available cache modes and configuration options.

Next steps

Increase the number of workers

Playwright's default configuration uses only 1 worker when it detects a CI environment. To make better use of the available cores, you can increase this for faster test execution. A good starting point is 75% of the available cores—adjust this depending on your workload:

- name: Run Playwright tests
  run: npx playwright test --workers 75%

You can also configure this in your Playwright configuration.

Upload test reports

Use namespace-actions/upload-artifact to upload Playwright's HTML report for easy debugging:

- uses: namespace-actions/upload-artifact@v1
  if: ${{ !cancelled() }}
  with:
    name: playwright-report
    path: playwright-report/
    retention-days: 30

The if: ${{ !cancelled() }} condition ensures the report is uploaded even when tests fail.

Full example

Here's a complete workflow using Namespace runners with caching:

name: Playwright Tests
 
on:
  push:
    branches: [main]
  pull_request:
 
jobs:
  test:
    timeout-minutes: 60
    runs-on: namespace-profile-playwright
    steps:
      - uses: namespacelabs/nscloud-checkout-action@v7
 
      - uses: actions/setup-node@v6
        with:
          node-version: lts/*
          package-manager-cache: false # Use Namespace toolchain caching instead
          cache: ""
 
      - name: Set up cache
        uses: namespacelabs/nscloud-cache-action@v1
        with:
          cache: |
            playwright
            apt
          path: |
            ~/.npm
 
      - name: Install dependencies
        run: npm ci
 
      - name: Install Playwright browsers
        run: npx playwright install --with-deps
 
      - name: Run Playwright tests
        run: npx playwright test --workers 75%
 
      - uses: namespace-actions/upload-artifact@v1
        if: ${{ !cancelled() }}
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30

View the full example repository at namespace-integration-demos/playwright.

Last updated