A production-ready Playwright automation framework built with TypeScript, following best practices and industry standards.
- β TypeScript with strict type safety
- β Page Object Model (POM) pattern
- β Multi-browser support (Chromium, Firefox, WebKit)
- β Mobile testing support (iOS and Android viewports)
- β
Environment configuration (dev, staging, prod) via
.envfiles - β Allure + Playwright HTML reporting
- β Video, screenshot, and trace on failure
- β Parallel execution and retries in CI
- β API testing capabilities
- β Data-driven testing with JSON
- β Custom fixtures for authenticated sessions
- β GitHub Actions CI/CD integration
.
βββ config/
β βββ playwright.config.ts # Playwright configuration
βββ env/
β βββ .env.dev # Development environment variables
β βββ .env.staging # Staging environment variables
βββ test-data/
β βββ users.json # Test data for data-driven tests
βββ tests/
β βββ api/
β β βββ users.api.spec.ts # API test examples
β βββ e2e/
β β βββ login.spec.ts # E2E test examples
β βββ fixtures/
β β βββ authenticatedUser.ts # Custom fixtures
β βββ pages/
β β βββ LoginPage.ts # Page Object Model - Login
β β βββ DashboardPage.ts # Page Object Model - Dashboard
β βββ utils/
β βββ apiClient.ts # API client utility
β βββ testData.ts # Test data utilities
βββ .github/
β βββ workflows/
β βββ playwright.yml # GitHub Actions CI workflow
βββ package.json
βββ tsconfig.json
βββ README.md
- Node.js 18+
- pnpm (recommended) or npm
-
Install dependencies:
pnpm install # or npm install -
Install Playwright browsers:
pnpm exec playwright install # or npx playwright install
-
Configure environment variables:
- Copy
.env.devand.env.stagingfiles - Update with your actual environment URLs and credentials
- Copy
# Run all tests
pnpm test
# Run tests in UI mode
pnpm test:ui
# Run tests in debug mode
pnpm test:debug
# Run tests in headed mode
pnpm test:headed
# Run tests for specific browser
pnpm test:chromium
pnpm test:firefox
pnpm test:webkit
# Run mobile tests
pnpm test:mobile
# Run API tests only
pnpm test:api
# Run E2E tests only
pnpm test:e2eSet the environment before running tests:
# Development
NODE_ENV=dev pnpm test
# Staging
NODE_ENV=staging pnpm test# View HTML report
pnpm report
# Generate Allure report
pnpm allure:generate
# Open Allure report
pnpm allure:open
# Serve Allure report (auto-generates)
pnpm allure:serveimport { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';
test('login test', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('username', 'password');
// ... assertions
});import { test, expect } from '../fixtures/authenticatedUser';
test('test with authenticated user', async ({ authenticatedPage, dashboardPage }) => {
await dashboardPage.verifyOnDashboard();
// User is already logged in
});import { test, expect } from '@playwright/test';
import { ApiClient } from '../utils/apiClient';
test('API test', async ({ request }) => {
const apiClient = new ApiClient(request);
const response = await apiClient.get('/users');
expect(response.status()).toBe(200);
});import { loadTestData } from '../utils/testData';
test('data-driven test', () => {
const testData = loadTestData();
for (const user of testData.validUsers) {
// Test with each user
}
});The main configuration is in config/playwright.config.ts. Key features:
- Multi-browser projects: Chromium, Firefox, WebKit
- Mobile projects: Pixel 5, iPhone 12
- Reporting: HTML, Allure, JSON
- Failure artifacts: Video, screenshots, traces
- CI optimizations: Retries, workers configuration
Strict TypeScript configuration with path aliases:
@tests/*βtests/*@config/*βconfig/*@utils/*βtests/utils/*@pages/*βtests/pages/*@fixtures/*βtests/fixtures/*
The workflow (.github/workflows/playwright.yml) includes:
- β Automatic test execution on push/PR
- β Parallel test execution with sharding
- β Artifact uploads (reports, screenshots, videos)
- β Allure report generation
- β pnpm support
Configure these secrets in GitHub:
BASE_URL: Base URL for testsAPI_BASE_URL: API base URLAPI_KEY: API authentication key
- Page Object Model: All page interactions are abstracted in Page classes
- Type Safety: Strict TypeScript ensures type safety
- Environment Management: Use
.envfiles for different environments - Test Data: Externalize test data in JSON files
- Reusable Utilities: Common functionality in utils
- Custom Fixtures: Reusable test setup/teardown
- Parallel Execution: Tests run in parallel for faster execution
- Failure Artifacts: Automatic capture of videos, screenshots, traces
pnpm test:debugTraces are automatically captured on failure. View them:
pnpm exec playwright show-trace trace.zipAutomatically saved in test-results/ directory on failure.
MIT