Professional test automation framework for Todo application using Playwright, TypeScript, and best practices for SDET (Software Development Engineer in Test).
π Latest Allure Report: View Online
- Overview
- Project Structure
- Prerequisites
- Setup
- Running Tests
- Test Reports
- Test Architecture
- Best Practices
- Configuration
- Troubleshooting
This framework implements a comprehensive testing strategy following the Testing Pyramid:
- API Tests (
tests/api/) - Test HTTP endpoints directly, verify API contracts, and validate database persistence - E2E Tests (
tests/e2e/) - Test user experience through browser automation, verify UI flows - Performance Tests (
tests/performance/) - Load, stress, and spike testing with k6 and TypeScript - Page Object Model (
tests/page-object-modal/) - Encapsulate UI interactions for maintainability
β
API Testing - Direct HTTP endpoint testing with database verification
β
E2E Testing - Full browser automation with Page Object Model
β
Performance Testing - Load, stress, and spike tests with k6 and TypeScript
β
TypeScript - Type-safe test code across all test types
β
PostgreSQL Integration - Direct database access for verification
β
Reusable Services - API and DB services for code reusability
β
Error Handling - Comprehensive error case testing
β
Test Data Management - Factory pattern for test data generation
β
Allure Reporting - Professional test reports with screenshots and attachments
tests/
βββ api/ # API test suites
β βββ todo.spec.ts # Todo API tests
β βββ user.spec.ts # User API tests
βββ e2e/ # E2E test suites
β βββ accessibility.spec.ts
β βββ authentication.spec.ts
β βββ security.spec.ts
β βββ todo-management.spec.ts
β βββ validation.spec.ts
βββ fixtures/ # Playwright fixtures
β βββ api.fixture.ts # API, DB, and page fixtures
βββ helpers/ # Helper utilities
β βββ testData.factory.ts # Test data generation
βββ models/ # TypeScript models
β βββ api/ # API response models
β βββ db/ # Database entity models
βββ page-object-modal/ # Page Object Model classes
β βββ LoginPage.ts
β βββ RegisterPage.ts
β βββ TodoPage.ts
β βββ ForgotPasswordPage.ts
β βββ ResetPasswordPage.ts
βββ services/ # Reusable services
βββ api/ # API service classes
β βββ TodoApiService.ts
β βββ UserApiService.ts
βββ db/ # Database service classes
βββ TodoDbService.ts
βββ UserDbService.ts
- Node.js >= 18.x
- PostgreSQL database (for database verification)
- Access to Todo App (backend API and frontend)
- k6 (for performance testing - see Installation)
- Java (for Allure reporting - optional, only if using Allure CLI)
npm installCopy .env.example to .env and fill in your values:
cp .env.example .envRequired environment variables:
BASE_URL- Frontend URL (default:http://localhost:3000)API_URL- Backend API URL (default:http://localhost:3000/api)DB_URL- PostgreSQL connection string
macOS (using Homebrew - Recommended):
brew install k6macOS (Manual Installation - If Homebrew doesn't work):
First, check your Mac architecture:
uname -mThen download and install:
For Intel Mac (x86_64):
# Download k6
curl -L https://github.com/grafana/k6/releases/latest/download/k6-v0.48.0-darwin-amd64.zip -o k6.zip
# Extract
unzip k6.zip
# Move to /usr/local/bin (requires sudo password)
sudo mv k6 /usr/local/bin/k6
# Clean up
rm k6.zip
# Verify installation
k6 versionFor Apple Silicon (M1/M2/M3 - arm64):
Option A: Use installation script (Easiest)
bash install-k6.shOption B: Manual installation
curl -L https://github.com/grafana/k6/releases/download/v0.48.0/k6-v0.48.0-darwin-arm64.tar.gz -o k6.tar.gz
tar -xzf k6.tar.gz
sudo mv k6-v0.48.0-darwin-arm64/k6 /usr/local/bin/k6
rm -rf k6.tar.gz k6-v0.48.0-darwin-arm64
k6 versionAlternative: Install to User Directory (No sudo required):
# Create local bin directory
mkdir -p ~/bin
# Download k6 (choose correct version for your Mac)
# For Intel Mac:
curl -L https://github.com/grafana/k6/releases/download/v0.48.0/k6-v0.48.0-darwin-amd64.tar.gz -o ~/k6.tar.gz
# OR for Apple Silicon:
# curl -L https://github.com/grafana/k6/releases/download/v0.48.0/k6-v0.48.0-darwin-arm64.tar.gz -o ~/k6.tar.gz
# Extract
cd ~ && tar -xzf k6.tar.gz && mv k6-v0.48.0-darwin-arm64/k6 ~/bin/k6
# Add to PATH (add to ~/.zshrc)
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# Clean up
rm -rf ~/k6.tar.gz ~/k6-v0.48.0-darwin-arm64
# Verify installation
k6 versionFor detailed installation instructions, see INSTALL_K6.md
Linux (Ubuntu/Debian):
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D9
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6Windows (using Chocolatey):
choco install k6Windows (Manual Installation): Download the latest release from: https://github.com/grafana/k6/releases Extract and add to PATH.
Verify installation:
k6 versionYou should see output like: k6 v0.48.0 (go1.21.5, darwin/amd64)
npx playwright installmacOS:
brew install allureWindows (using Scoop):
scoop install allureLinux:
# Download from https://github.com/allure-framework/allure2/releases
# Or use package manager# Run ALL tests (API + E2E + Performance smoke)
npm test
# Or explicitly:
npm run test:all
# Run only Playwright tests (API + E2E)
npm run test:playwright
# Run only API tests
npm run test:api
# Run only E2E tests
npm run test:e2e
# Run only Performance tests
npm run test:performance:smoke # Smoke test (quick validation)
npm run test:performance:load # Load test (normal expected load)
npm run test:performance:stress # Stress test (beyond normal capacity)
npm run test:performance:spike # Spike test (sudden traffic spikes)
# View performance reports
npm run test:performance:report # List all generated HTML reports
npm run test:performance:report:open # Open all HTML reports in browser
# Or open specific report manually:
# open performance-report-smoke.html
# open performance-report-load.html
# open performance-report-stress.html
# open performance-report-spike.htmlRuns all test types: API, E2E, and Performance (smoke)
npm test
# or explicitly:
npm run test:allThis will run:
- β API Tests (Playwright) - Tests HTTP endpoints with database verification
- β E2E Tests (Playwright) - Tests user experience through browser automation
- β Performance Tests (k6) - Smoke test for quick validation
npm run test:apiTests HTTP endpoints directly, verifies API contracts, and validates database persistence.
npm run test:e2eTests user experience through browser automation with Page Object Model.
# Smoke test (quick validation) - included in npm test
npm run test:performance:smoke
# Load test (normal expected load)
npm run test:performance:load
# Stress test (beyond normal capacity)
npm run test:performance:stress
# Spike test (sudden traffic spikes)
npm run test:performance:spike
# All performance tests
npm run test:performance:allPerformance Reports: k6 automatically generates HTML reports for each test run using k6-reporter:
performance-report-smoke.html- Smoke test resultsperformance-report-load.html- Load test resultsperformance-report-stress.html- Stress test resultsperformance-report-spike.html- Spike test results
Each HTML report includes:
- Request statistics (duration, rate, failures)
- Threshold results
- Custom metrics
- Summary statistics
- Visual charts and graphs
View reports:
npm run test:performance:report # List all reports
npm run test:performance:report:open # Open all reports in browserFor detailed performance testing documentation, see tests/performance/README.md.
npm run test:playwrightThis runs all Playwright tests (API and E2E) but excludes performance tests.
# Smoke test (quick validation)
npm run test:performance:smoke
# Load test (normal expected load)
npm run test:performance:load
# Stress test (beyond normal capacity)
npm run test:performance:stress
# Spike test (sudden traffic spikes)
npm run test:performance:spikeFor detailed performance testing documentation, see tests/performance/README.md.
npm run test:uinpm run test:headednpm run test:debugView the default Playwright HTML report:
npm run test:reportThis opens the HTML report in your browser with:
- Test execution timeline
- Screenshots for failed tests
- Trace viewer for debugging
- Test results summary
Generate and view Allure report:
npm run test:report:allureThis will:
- Generate Allure report from test results
- Open it in your default browser
Allure Report Features:
- πΈ Screenshots - Automatic screenshots for failed tests
- π Attachments - Request/response data, logs, etc.
- π·οΈ Tags - Test categorization (epic, feature, story)
- π History - Track test execution over time
- π Filtering - Filter by status, severity, tags
- π Charts - Visual representation of test results
Allure Report Structure:
- Overview - Summary with charts and statistics
- Suites - Test suites organized by categories
- Graphs - Visual charts (duration, status, etc.)
- Timeline - Test execution timeline
- Behaviors - Tests organized by epic/feature/story
- Packages - Tests organized by package structure
Purpose: Test HTTP endpoints directly, verify API contracts, and validate database persistence.
Approach:
- Make HTTP request via API service
- Verify API response (status code, structure, data)
- Verify database state (optional but recommended for critical operations)
Example:
test('should create a new user', async ({ userApi, userDb }) => {
await allure.epic('User Management');
await allure.feature('User Registration');
// 1. API call
await userApi.register({ username, email, password });
// 2. Verify API response
const loginResponse = await userApi.login({ username, password });
expect(loginResponse.accessToken).toBeDefined();
// 3. Verify database
const dbUser = await userDb.getUserById(loginResponse.user.id);
expect(dbUser?.username).toBe(username);
});Purpose: Test user experience through browser automation.
Approach:
- Use Page Object Model for UI interactions
- Verify UI state (elements visible, text correct, navigation)
- Use API/DB only for setup/cleanup (not for verification)
Example:
test('should create a new todo', async ({ page }) => {
await allure.epic('Todo Management');
await allure.feature('Todo CRUD');
const todoPage = new TodoPage(page);
// UI interaction
await todoPage.addTodo('Test Todo');
// UI verification
await expect(page.locator('text=Test Todo')).toBeVisible();
});All UI interactions are encapsulated in Page Object classes located in tests/page-object-modal/.
Benefits:
- Reusable UI interaction code
- Easy maintenance when UI changes
- Clear separation of concerns
Purpose: Test system performance, capacity, and stability under various load conditions.
Approach:
- Smoke Tests - Quick validation that system is accessible
- Load Tests - Test normal expected load (10-50 concurrent users)
- Stress Tests - Find breaking point and verify recovery (up to 50+ users)
- Spike Tests - Test sudden traffic spikes (1 to 100 users)
Tools: k6 with TypeScript support
Example:
import { Options } from 'k6/options';
import { login, getAllTodos } from '../helpers/api.helper';
export const options: Partial<Options> = {
vus: 10,
duration: '5m',
};
export default function () {
const loginResponse = login('username', 'password');
if (loginResponse) {
getAllTodos(loginResponse.accessToken);
}
}See tests/performance/README.md for detailed documentation.
- API tests focus on API contracts and database verification
- E2E tests focus on user experience and UI flows
- No duplication between API and E2E tests
- Test both success and error cases
- Verify proper HTTP status codes (400, 401, 403, 404, 500)
- Test edge cases and boundary conditions
- Use unique test data (timestamps, random strings)
- Clean up test data after tests (afterAll hooks)
- Use factories for test data generation
- Use service classes for API and DB operations
- Use Page Objects for UI interactions
- Share fixtures across tests
- TypeScript for type safety
- Clear naming conventions
- Comprehensive comments and documentation
- Use Allure for professional reports
- Add screenshots for failed tests
- Attach request/response data for API tests
- Use tags for test categorization
Main configuration file: playwright.config.ts
Key settings:
testDir:./tests- Test directorytimeout: 30000ms - Test timeoutretries: 1 (local) / 2 (CI) - Retry failed testsprojects: Separate projects for API and E2E testsreporter: HTML + Allure reporters
See .env.example for all available environment variables.
- Increase timeout in
playwright.config.ts - Check if application is running
- Verify database connection
- Verify
DB_URLin.envfile - Check PostgreSQL is running
- Verify connection string format
- Verify
API_URLis correct - Check if backend server is running
- Verify authentication tokens are valid
- Verify
BASE_URLis correct - Check if frontend is running
- Verify browser is installed (
npx playwright install)
- Ensure
allure-playwrightis installed - Check that tests have run and generated results in
allure-results/ - Verify Allure CLI is installed (for viewing reports)
- Try:
allure generate allure-results --clean -o allure-report
- All documentation and code comments are in English
- Test data is automatically cleaned up after tests
- Tests are designed to be independent and parallelizable
- Framework follows SDET best practices for enterprise applications
- HTML reports for Playwright tests (via Allure) and k6 HTML reports for performance tests
When adding new tests:
- Follow existing patterns (API vs E2E separation)
- Use Page Object Model for UI tests
- Add error handling tests
- Clean up test data
- Add Allure tags (epic, feature, story, severity)
- Update documentation
ISC