This document outlines the steps taken to add Playwright testing to the nypl-header-app repository.
- Node.js and npm installed
- Existing project setup
1. Install Playwright - NOTE: This procedure was used when first setting this up. Develops who install this repo won't have to do these steps, as Playwright will be installed for them with npm install.
Install Playwright as a dev dependency:
npm install -D @playwright/test@latestInstall the browser binaries and system dependencies:
npx playwright install --with-depsThis installs:
- Chromium
- Firefox
- WebKit
- Required system dependencies
Created playwright.config.ts in the project root with the following settings:
- Test Directory:
./e2e- All Playwright tests will be placed here - Browsers: Configured to run tests on Chromium, Firefox, and WebKit
- Base URL:
http://localhost:5173- Matches the local dev server - Web Server: Automatically starts
npm run devbefore running tests - CI Settings:
- Retries: 2 retries on CI, 0 locally
- Workers: 1 worker on CI for stability
forbidOnly: Prevents accidentally committingtest.only()
- Reporter: HTML reporter for viewing test results
- Trace: Enabled on first retry for debugging failures
Created the following structure:
e2e/
├── README.md # Documentation for running tests
└── example.spec.ts # Example test file (placeholder)
e2e/README.md includes common commands:
- Running all tests
- Running in UI mode
- Running in headed mode
- Running specific test files
- Debugging tests
- Viewing test reports
e2e/example.spec.ts is a placeholder test file ready for actual test implementation.
Created .github/workflows/playwright.yml to run tests on CI:
Trigger Events:
- Push to
mainorproductionbranches - Pull requests to
mainorproductionbranches
Workflow Steps:
- Checkout code
- Setup Node.js (LTS version)
- Install dependencies with
npm ci - Install Playwright browsers with
npx playwright install --with-deps - Run Playwright tests
- Upload test reports as artifacts (retained for 30 days)
Configuration:
- Runs on:
ubuntu-latest - Timeout: 60 minutes
# Run all tests
npx playwright test
# Run tests in UI mode (interactive)
npx playwright test --ui
# Run tests in headed mode (see browser)
npx playwright test --headed
# Run a specific test file
npx playwright test e2e/example.spec.ts
# Run tests in a specific browser
npx playwright test --project=chromium# Run tests in debug mode
npx playwright test --debug
# Show HTML test report
npx playwright show-reportCreate new test files in the e2e/ directory with the .spec.ts extension:
import { test, expect } from "@playwright/test";
test.describe("Feature Name", () => {
test("should do something", async ({ page }) => {
await page.goto("/");
// Your test assertions here
});
});playwright.config.ts- Main Playwright configuratione2e/README.md- Test documentatione2e/example.spec.ts- Placeholder test file.github/workflows/playwright.yml- GitHub Actions workflow
@playwright/test- Playwright testing framework (dev dependency)
- Write actual E2E tests in the
e2e/directory - Remove or update
e2e/example.spec.tswith real tests - Adjust
playwright.config.tssettings as needed for your specific use case - Consider adding more browser configurations (mobile viewports, branded browsers)
- Update the GitHub Actions workflow if custom environment variables or secrets are needed