A reference template for learning Playwright with TypeScript. Includes web and API tests, Page Object Model, test data management, Qase integration, Beacon HTML reporting and CI-ready configuration.
The latest Beacon HTML report from main is published on GitHub Pages and refreshed on every successful push to main:
Direct link: https://estefafdez.com/playwright-template/
CI also uploads the beacon-report/ folder as a workflow artifact on every run (30-day retention). To generate the report locally, run npm test and open it with npx beacon open beacon-report.
- Node.js 24+
- npm 9+
npm install
npx playwright installCreate a .env file in the root with the required variables:
REQRES_API_KEY=your_api_key # only needed when running against https://reqres.in
TESTDINO_TOKEN=your_testdino_token # optional: TestDino reporting
API_BASE_URL=http://localhost:3000 # optional: run the API tests against the local mock API| Command | Description |
|---|---|
npm test |
Run all tests |
npm run test:web |
Web tests only |
npm run test:api |
API tests only |
npm run api:local |
Start the local mock API on http://localhost:3000 |
npm run test:api:local |
API tests against the local mock API (no rate limits) |
npm run ui |
Open the Playwright interactive UI mode |
npm run debug |
Run in debug mode (step by step) |
npm run report |
Open the last HTML report |
playwright-template/
├── data/ # Reusable test data
│ ├── testData.ts # Data for web tests (forms, etc.)
│ └── users/ # User data for API tests (JSON)
├── elements/ # Locators organised by page area
│ ├── FormElements.ts
│ ├── HomeElements.ts
│ ├── NavigationElements.ts
│ └── TodoElements.ts
├── local-api/ # Local mock API compatible with reqres.in
├── helpers/ # Shared utilities
│ ├── api-helpers.ts # HTTP client and schema validators
│ └── api-setup.ts # Delay helper to avoid rate limiting
├── pages/ # Page Objects (actions per page)
│ ├── ContactPage.ts
│ ├── HomePage.ts
│ ├── NavigationPage.ts
│ └── TodoPage.ts
├── tests/
│ ├── api/ # REST API tests (GET, POST, PUT, PATCH, DELETE)
│ └── web/ # Web UI tests
├── types/ # Shared TypeScript types
├── playwright.config.ts # Playwright configuration
└── .env # Environment variables (do not commit)
| Project | Base URL | Tests |
|---|---|---|
web |
https://testing.qaautomationlabs.com | tests/web/ |
api |
https://reqres.in (or API_BASE_URL when set) |
tests/api/ |
The API tests hit reqres.in by default, whose free plan
applies rate limits (HTTP 429 once the quota is exhausted). To run them without
external limits, this template ships a zero-dependency local mock of that API in
local-api/:
npm run test:api:localThe Playwright config starts the mock automatically when API_BASE_URL points
to localhost, so no test code changes are needed; the same specs run against
either backend.
- Page Object Model (POM): pages encapsulate actions, elements encapsulate locators
- Separated test data:
data/keeps inputs out of test files - API helpers: reusable HTTP client with schema and response-time validation
- Environment-based config:
baseURLis defined inplaywright.config.ts, not in code - Qase integration: tests carry their ID in brackets
[N, Suite] - CI with GitHub Actions: runs on pushes and PRs to
main, on a Monday/Wednesday/Friday schedule and on manual dispatch; successful pushes tomainpublish the Beacon report to GitHub Pages
