Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Playwright CI/CD Integration

Playwright CI/CD Integration

This chapter introduces how to integrate Playwright tests into CI/CD pipelines, including GitHub Actions and other common CI platforms.


GitHub Actions integration

When you choose to add GitHub Actions in npm init playwright@latest , Playwright automatically generates a workflow configuration.

Auto-generated workflow

Example

File path: .github/workflows/playwright.yml

name

:

Playwright Tests

on

:

  push

:

    branches

:

[

main, master

]

  pull_request

:

    branches

:

[

main, master

]

jobs

:

  test

:

    timeout-minutes

:

60

    runs-on

:

ubuntu-latest

    steps

:

      - uses

:

actions/checkout@v4      

1. Check out code

      - uses

:

actions/setup-node@v4    

2. Install Node.js

        with

:

          node-version

:

20

      - name

:

Install dependencies

        run

:

npm ci                    

3. Install dependencies

      - name

:

Install Playwright Browsers

        run

:

npx playwright install --with-deps  

4. Install browsers and system dependencies

      - name

:

Run Playwright tests

        run

:

npx playwright test        

5. Run tests

      - uses

:

actions/upload-artifact@v4

        if

:

always

(

)

                   

6. Upload test reports (even if tests fail)

        with

:

          name

:

playwright-report

          path

:

playwright-report/

          retention-days

:

30


View CI test results

View test logs

On the Actions page of a GitHub repository, click on each run to view detailed test logs.

Each Worker's output is displayed independently, making it easy to locate specific failing tests.

View the HTML report

If configured, you can reporter: 'html'download it from Artifacts playwright-report/ to view the full HTML report locally.

Publish reports to the web

Example

File path: .github/workflows/playwright.yml

Deploy the HTML report to GitHub Pages (simplified example)

:

Upload report

  uses

:

actions/upload-artifact@v4

  if

:

always

(

)

  with

:

    name

:

playwright-report

    path

:

playwright-report/

    retention-days

:

30


Other CI platforms

Jenkins



pipeline {

  agent any

  stages {

    stage('Install') {

      steps {

        sh 'npm ci'

        sh 'npx playwright install --with-deps'

      }

    }

    stage('Test') {

      steps {

        sh 'npx playwright test'

      }

    }

  }

  post {

    always {

      archiveArtifacts artifacts: 'playwright-report/**'

      junit 'test-results/junit.xml'

    }

  }

}

GitLab CI

Example

File path: .gitlab-ci.yml

playwright-tests

:

  image

:

mcr.microsoft.com/playwright:v1.52.0-jammy

  script

:

   - npm ci

    - npx playwright test

  artifacts

:

    when

:

always

    paths

:

     - playwright-report/

    expire_in

:

30

days


Running Playwright with Docker

Microsoft provides official Docker images with all system dependencies preinstalled, ready to use out of the box.

Use the official image



# Pull image

docker pull mcr.microsoft.com/playwright:v1.52.0-jammy



# Run tests in container

docker run --rm -v $(pwd):/work -w /work \

  mcr.microsoft.com/playwright:v1.52.0-jammy \

  npx playwright test

Dockerfile example

Example

File path: Dockerfile

FROM mcr.microsoft.com

/

playwright:v1.52.0-jammy

WORKDIR

/

app

COPY package.json package-lock.json .

/

RUN npm ci

COPY . .

CMD

[

"npx"

,

"playwright"

,

"test"

]


CI environment best practices

Practice Description
Use --with-deps npx playwright install --with-deps Automatically install Linux system dependencies
Lock the Playwright version in package.json Lock the version in @playwright/test to avoid unexpected upgrades on CI
Cache browsers Caching ms-playwright directory to avoid downloading browsers every time
Control the number of workers Use workers: process.env.CI ? 1 : undefined Control resource usage on CI
Setting Timeouts The CI environment is slower than local, so appropriately increase the timeout and retries
Preserve test artifacts Upload traces, screenshots, videos, and reports as CI Artifacts