Playwright Workers | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Building a Framework
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore the concept of workers in Playwright, which are essential for running tests efficiently. A worker is essentially a process that executes your tests, similar to a single thread or executor. Key Concepts of Workers Single Worker: Executes tests sequentially. Multiple Workers: Created to run tests in parallel, enhancing performance. Configuration Settings In the playwright.config.ts file, two important settings govern worker behavior: fullyParallel: When set to false , tests within a spec file run sequentially. If set to true , tests can run in parallel. workers: Defines the number of workers. If set to undefined , Playwright will use half of the available CPU cores. For example, a MacBook Pro with an M1 chip (10 cores) will utilize up to 5 workers. Running Tests When running tests: With fullyParallel: false and workers: undefined , tests execute sequentially within each spec file. Setting fullyParallel: true allows tests to run concurrently, increasing execution speed. Using a single worker means tests will always run sequentially, regardless of the fullyParallel setting. Worker Lifecycle When a test fails, Playwright reinitializes the worker to ensure a clean environment for subsequent tests. This is crucial for maintaining test reliability. For API testing , it is recommended to use a single worker to avoid flakiness caused by parallel execution, as API tests are generally faster than UI tests. In the next lesson, we will delve deeper into managing user authorization using workers.