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