Skip to main content

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:
Key Components:
  • 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
From the source code (src/common/test.ts:45-70):

Test Execution Model

The test runner executes tests through several phases:
  1. Configuration Loading: Loads and validates playwright.config.ts
  2. Test Discovery: Scans for test files matching patterns
  3. Test Compilation: Transpiles TypeScript/JSX to JavaScript
  4. Worker Pool Creation: Spawns worker processes based on configuration
  5. Test Distribution: Assigns tests to workers
  6. Execution: Runs tests in parallel across workers
  7. 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:
Worker Characteristics:
  • 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
From src/common/config.ts:240-252:

Test Types and Organization

Playwright provides several test organization patterns: Serial Execution:
Parallel Execution:
Conditional Execution:

Test Lifecycle

Each test goes through a defined lifecycle:

Test Metadata

Each test maintains rich metadata:
From 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

Tests running in the same worker share the browser instance but get separate contexts. For complete isolation, use separate workers.

Performance Optimization

The test runner includes several optimizations: Shard Tests Across Machines:
Fully Parallel Mode:
Worker Reuse: Workers reuse the browser instance across tests for better performance.

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