Running Playwright Tests in GitHub Actions
You'll learn how to automate your Playwright tests so they run automatically on every code change, catching bugs before they reach production.
Why CI/CD for E2E Tests Matters
You've built comprehensive Playwright tests using the Page Object pattern. But if they only run on your local machine, they can't protect your team from breaking changes. GitHub Actions turns your tests into an automated safety net that runs on every push and pull request.
Think of it like a security checkpoint at an airport: every commit must pass through your test suite before merging, ensuring nothing broken slips through.
Setting Up the Workflow
Create .github/workflows/playwright.yml in your repository:
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: '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
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
This workflow checks out your code, installs dependencies with caching (cache: 'npm' speeds up subsequent runs), installs Playwright browsers, runs your tests, and uploads test reports even if tests fail (if: always()).
The npm ci command ensures clean, reproducible installs—perfect for CI environments.
Key Takeaway: GitHub Actions workflows automate Playwright tests on every push/PR, with proper caching and artifact retention ensuring fast feedback and accessible test reports when failures occur.