mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
64 lines
1.8 KiB
Markdown
64 lines
1.8 KiB
Markdown
---
|
|
id: test-parallel
|
|
title: "Parallelism and sharding"
|
|
---
|
|
|
|
Playwright Test runs tests in parallel by default, using multiple worker processes.
|
|
|
|
<!-- TOC -->
|
|
|
|
## Workers
|
|
|
|
Each worker process creates a new environment to run tests. By default, Playwright Test reuses the worker as much as it can to make testing faster.
|
|
|
|
However, test runner will create a new worker when retrying tests, after any test failure, to initialize a new environment, or just to speed up test execution if the worker limit is not reached.
|
|
|
|
You can control the maximum number of worker processes via [command line](./test-cli.md) or in the [configuration file](./test-configuration.md).
|
|
|
|
- Run in parallel by default
|
|
```bash
|
|
npx playwright test
|
|
```
|
|
|
|
- Disable parallelization
|
|
```bash
|
|
npx playwright test --worker 1
|
|
```
|
|
|
|
- Control the number of workers
|
|
```bash
|
|
npx playwright test --worker 4
|
|
```
|
|
|
|
- In the configuration file
|
|
```js
|
|
// playwright.config.js
|
|
module.exports = {
|
|
// Limit the number of workers on CI, use default locally
|
|
workers: process.env.CI ? 2 : undefined,
|
|
};
|
|
```
|
|
|
|
```ts
|
|
// playwright.config.ts
|
|
import { PlaywrightTestConfig } from 'playwright/test';
|
|
|
|
const config: PlaywrightTestConfig = {
|
|
// Limit the number of workers on CI, use default locally
|
|
workers: process.env.CI ? 2 : undefined,
|
|
};
|
|
export default config;
|
|
```
|
|
|
|
Each worker process is assigned a unique sequential index that is accessible through the [`workerInfo`](./test-advanced.md#workerinfo) object.
|
|
|
|
## Shards
|
|
|
|
Playwright Test can shard a test suite, so that it can be executed on multiple machines. For that, pass `--shard=x/y` to the command line. For example, to split the suite into three shards, each running one third of the tests:
|
|
|
|
```bash
|
|
npx playwright test --shard=1/3
|
|
npx playwright test --shard=2/3
|
|
npx playwright test --shard=3/3
|
|
```
|