Playwright Github Actions Workflow

Every QA Automation Engineer or Software Development Engineer in Test (SDET) needs to understand how to set up and manage workflows or pipelines from scratch. Having this capability ensures that automated tests are consistently run and maintained, which is crucial for maintaining software quality.

Here, we provide a working example of a GitHub Actions workflow for running Playwright tests. This setup will help you automate the process of running tests on different browsers whenever code is pushed or a pull request is made.

GitHub Actions Workflow for Playwright Tests
The following GitHub Actions workflow is designed to run Playwright tests on different browsers. The workflow is triggered on pushes and pull requests to the main or master branches, and can also be manually triggered with a specified browser.
name: Playwright Tests
on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
  workflow_dispatch:
    inputs:
      browser:
        type: choice
        description: Which browser to test
        required: true
        options:
          - firefox
          - chromium
          - webkit

jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      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 --project ${{ github.event.inputs.browser }}
    - uses: actions/upload-artifact@v4
      if: always()
      with:
        name: playwright-report
        path: playwright-report/
        retention-days: 30
Explanation of the Workflow:

1. Triggering Events
The on section defines when the workflow should be triggered:
  • push: Triggers the workflow when code is pushed to the main or master branches.
  • pull_request: Triggers the workflow when a pull request is made to the main or master branches.
  • workflow_dispatch: Allows manual triggering of the workflow with specified inputs.

2. Job Definition
The jobs section defines the individual jobs that will run as part of the workflow:
  • test: The name of the job that will run the Playwright tests.

3. Job Configuration
The test job is configured with the following properties:
  • timeout-minutes: Sets a timeout of 60 minutes for the job.
  • runs-on: Specifies that the job should run on the latest Ubuntu runner.

4. Job Steps
The steps section defines the steps that the job will execute:
  • Checkout the Code:
- uses: actions/checkout@v4
This step checks out the repository code so that it can be used in subsequent steps.

  • Set Up Node.js:
- uses: actions/setup-node@v4
  with:
    node-version: lts/*
This step sets up Node.js using the latest LTS (Long Term Support) version.

  • Install Dependencies:
- name: Install dependencies
  run: npm ci
This step installs the project dependencies using npm ci, which is optimized for CI environments.

  • Install Playwright Browsers:
- name: Install Playwright Browsers
  run: npx playwright install --with-deps
This step installs the necessary browsers for Playwright to run the tests.

  • Run Playwright Tests:
- name: Run Playwright tests
  run: npx playwright test --project ${{ github.event.inputs.browser }}
This step runs the Playwright tests. The --project flag specifies the browser to use for the tests, which is provided as an input when the workflow is manually triggered.

  • Upload Test Artifacts:
- uses: actions/upload-artifact@v4
  if: always()
  with:
    name: playwright-report
    path: playwright-report/
    retention-days: 30
This step uploads the Playwright test report as an artifact. The if: always() condition ensures that the report is uploaded even if the tests fail. The artifact is retained for 30 days.
Schedule a FREE 30-minute consultation with Sergii to discuss your testing career and job opportunities.
Limited slots are available!
We help ambitious people to get into Tech with no prior experience.