This project is a robust, scalable Playwright-based automation framework for UI, API, and E2E testing. It supports:
- Multi-environment configuration
- Allure reporting
- Video, screenshot, and trace artifact management
- Advanced utilities for data, network, and reporting
- CI/CD integration for GitHub Actions, AWS CodeBuild, Azure DevOps, and Google Cloud Build
- Install dependencies:
npm install
- Run all tests:
npx playwright test - Generate and view Allure report:
npx allure generate allure-results --clean -o allure-report npx allure open allure-report
src/- Page objects and service classes (e.g., BasePage, BaseApiService)tests/- Test cases for UI, API, E2E, fixtures, and hookstest-data/- Static and dynamic test data (JSON, CSV, data generators)utils/- Utility functions and helpers for API, assertions, config, data generation, DB, error handling, file helpers, formatters, framework, performance, reporting, web, and securityscreenshots/- Screenshots from test runs, organized by date/time and test namevideos/- Test run videos, organized by date/time and test nametrace/- Playwright trace files, organized by date/time and test nameallure-results/- Raw Allure results for reportingallure-report/- Generated Allure HTML reportlogs/- Log files for each test run.env.*- Environment-specific variables (development, staging, production)
Use .env.development, .env.staging, or .env.production to set environment-specific variables.
Never commit secrets; set them in your CI/CD provider.
- Run lint:
npx eslint . - Run format:
npx prettier --write .
npm test- Run all testsnpm run allure:report- Generate and open Allure report
const { test, expect } = require('@playwright/test');
const BasePage = require('../../src/pages/BasePage');
const { takeScreenshot } = require('../../utils/framework/screenshotUtils');
const { mockRoute } = require('../../utils/web/networkHelper');
test('UI demo', async ({ page }, testInfo) => {
const basePage = new BasePage(page);
await mockRoute(page, /\/api\/user/, { id: 1, name: 'Mocked User' });
await basePage.goto('https://playwright.dev');
await expect(page).toHaveTitle(/Playwright/);
await takeScreenshot(page, testInfo.title);
});const { test, expect } = require('@playwright/test');
const BaseApiService = require('../../src/services/BaseApiService');
const { buildUser } = require('../../utils/data-generators/userFactory');
test('API demo', async () => {
const api = new BaseApiService('https://jsonplaceholder.typicode.com');
const testUser = buildUser();
const response = await api.post('/users', testUser);
expect(response.status()).toBe(201);
});- Screenshots:
screenshots/<date_time>/<testName>.png - Videos:
videos/<date_time>/<testName>.webm - Traces:
trace/<date_time>/<testName>.zip - Allure HTML Report: Downloadable from CI/CD artifacts
Sharding allows you to split your test suite across multiple CI jobs for faster execution.
- To run 2 shards (split tests in half):
npx playwright test --shard=1/2 npx playwright test --shard=2/2
- You can configure this in your CI/CD for maximum speed.
- Installs dependencies and browsers
- Runs tests
- Uploads all artifacts (screenshots, videos, traces, allure-results, allure-report)
- Same as above, with artifact collection
- Same as above, with artifact publishing
- Same as above, with artifact upload to GCS
- screenshotUtils.js: Save screenshots, videos, and traces in organized folders
- userFactory.js: Generate random user data for tests
- networkHelper.js: Mock and modify network requests
- logger.js: Structured logging
- errorHandler.js: Centralized error handling
- allureHelpers.js: Allure step/category/attachment helpers
- Allure Reporting: Rich HTML reports with steps, attachments, and environment info
- Custom Fixtures: Easily extend Playwright fixtures for authentication, setup, etc.
- Global Setup/Teardown: Seed DB, set up environment, and clean up after tests
- Performance Metrics: Collect web vitals in UI tests
- Artifacts not found?
Ensure the relevant folders exist before publishing artifacts in CI. - Allure report not opening?
Make sure you generate the report withnpx allure generatebefore opening. - Environment variables not working?
Set them in your CI/CD provider or in the correct.env.*file.
- Keep tests independent and idempotent
- Use data factories for test data
- Use sharding and parallelism for speed in CI
- Always review Allure reports for failed runs
- Store secrets only in CI/CD, never in code
// playwright.config.js
module.exports = {
testDir: './tests',
timeout: 30000,
retries: 1,
reporter: [['list'], ['allure-playwright']],
globalSetup: require.resolve('./tests/hooks/globalSetup.js'),
globalTeardown: require.resolve('./tests/hooks/globalTeardown.js'),
use: {
baseURL: process.env.BASE_URL || 'https://playwright.dev',
headless: true,
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
{ name: 'Desktop Chrome', use: { ...devices['Desktop Chrome'] } },
{ name: 'Desktop Firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'Desktop Safari', use: { ...devices['Desktop Safari'] } },
{ name: 'Mobile Chrome', use: { ...devices['Pixel 5'] } },
{ name: 'Mobile Safari', use: { ...devices['iPhone 12'] } },
],
};- Fork the repo and create a feature branch
- Add/modify tests and utilities as needed
- Run all tests and ensure CI passes
- Submit a pull request with a clear description
For more details, see the code comments and utility documentation in each file.
If you need more advanced examples or want to extend the framework, check the utils/ and tests/ folders for patterns and best practices.