Introduction
Playwright Test Runner is a full-featured test runner designed specifically for end-to-end testing. It provides a robust test execution engine with built-in parallelization, retries, fixtures, and reporters.Core Concepts
Test Structure
Playwright organizes tests in a hierarchical structure:- Root Suite: Top-level container for all tests
- Project Suite: Groups tests by project configuration
- File Suite: Represents a single test file
- Describe Blocks: Logical groupings within files
- Test Cases: Individual test functions
src/common/test.ts:45-70):
Test Execution Model
The test runner executes tests through several phases:- Configuration Loading: Loads and validates
playwright.config.ts - Test Discovery: Scans for test files matching patterns
- Test Compilation: Transpiles TypeScript/JSX to JavaScript
- Worker Pool Creation: Spawns worker processes based on configuration
- Test Distribution: Assigns tests to workers
- Execution: Runs tests in parallel across workers
- Reporting: Aggregates results and generates reports
The test runner uses worker processes for isolation. Each worker maintains its own context and can run multiple tests sequentially.
Worker Architecture
Playwright uses a worker-based parallelization model:- Each worker is an isolated Node.js process
- Workers run tests from a single project sequentially
- Worker-scoped fixtures are shared across tests in the same worker
- Test-scoped fixtures are created fresh for each test
src/common/config.ts:240-252:
Test Types and Organization
Playwright provides several test organization patterns: Serial Execution:Test Lifecycle
Each test goes through a defined lifecycle:Test Metadata
Each test maintains rich metadata:src/common/test.ts:257-284:
Test Isolation
Playwright provides multiple levels of isolation:Browser Context Isolation
Each test gets a fresh browser context:Storage State Management
Performance Optimization
The test runner includes several optimizations: Shard Tests Across Machines:Next Steps
Configuration
Configure the test runner for your needs
Test Fixtures
Learn about the fixture system
Assertions
Explore assertion methods
Test Hooks
Set up and tear down with hooks
