Playwright GitHub Actions
An automatic kitchen crew starts cooking the moment a new order arrives. GitHub Actions plays that role for tests. Each time a developer pushes code or opens a pull request, a fresh virtual machine wakes up, installs the project, runs every Playwright test, and reports the result on the pull request page.
The Workflow Pipeline
Developer pushes code
|
v
GitHub starts a workflow
|
v
Virtual machine boots (Ubuntu)
|
v
Install Node, packages, browsers
|
v
Run Playwright tests
|
v
Upload the HTML report
|
v
Green check or red cross on the pull request
Where the Workflow Lives
GitHub reads YAML files from the .github/workflows folder. The Playwright installer can generate a starter file, and the example below shows the same ideas written by hand.
A Complete Workflow File
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install packages
run: npm ci
- name: Install browsers
run: npx playwright install --with-deps
- name: Run tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 14
Reading the File Piece by Piece
Triggers
The on block lists the events that start the workflow. This file runs on pushes to the main branch and on pull requests aimed at it.
Runner
The runs-on line picks the machine type. ubuntu-latest gives a Linux machine that suits browser testing.
Steps
Each step either borrows a ready-made action through uses or runs a command through run. The npm ci command installs exact package versions from the lock file.
Browser Install
The --with-deps flag adds the operating system libraries that browsers need.
Artifacts
The upload step saves the HTML report. The condition !cancelled() keeps the upload running even when tests fail, which matters most when a report is needed.
Using Secrets
Passwords and tokens belong in the repository settings under Secrets. The workflow passes them to the tests as environment variables.
- name: Run tests
run: npx playwright test
env:
BASE_URL: ${{ secrets.STAGING_URL }}
USER_PASSWORD: ${{ secrets.TEST_PASSWORD }}
Running in Shards
A matrix creates several jobs at once. Each job runs one slice of the suite.
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- run: npx playwright test --shard=${{ matrix.shard }}/4
A Real-World Scenario
A team of eight developers merges about twenty pull requests per day. Each pull request triggers the workflow. A reviewer sees a green check within ten minutes and approves the change with confidence. A red cross blocks the merge until the author fixes the failure, so broken features rarely reach the main branch.
Quick Practice Task
Create the workflow file in a small repository that holds one Playwright test. Push the code, open the Actions tab on GitHub, and download the uploaded report from the finished run.
Common Questions
Why does the workflow fail on browser launch?
The runner lacks system libraries. Run npx playwright install --with-deps so the installer adds them.
How can a team speed up the job?
Cache npm packages, run shards in a matrix, and install only the browsers that the suite needs.
Where does a person find the report?
Open the finished run on the Actions tab, scroll to Artifacts, and download the zip. Unpack it and open index.html.
Key Takeaways
- A workflow file in
.github/workflowsdefines the automatic pipeline. - Triggers, a runner, and steps form the skeleton of every workflow.
- Artifacts preserve reports and traces for later review.
- Secrets keep credentials out of the repository.
