Run browser tests in parallel: workers on one machine, shards across many
Answer first
On one machine, run browser tests in parallel with Playwright Test's worker processes (by default half the logical CPU cores) or pytest-xdist. Across machines, split the suite with --shard=x/y, one shard per machine or sandbox, and set fullyParallel so shards get an even share.
- Published
- Updated
- min
- 6
Running browser tests in parallel means two different things: more browsers at once on one machine, and splitting the suite across several machines. Each browser needs its own CPU and memory, so the first route stops where the machine runs out, and the second takes over.
How do I run Playwright tests in parallel on one machine?
Run them in Playwright Test's worker processes, which are on by default. Playwright: "All workers have identical environments and each starts its own browser", and workers are "OS processes, running independently, orchestrated by the test runner" (Playwright parallelism, read 2026-11-26). The number of workers "Defaults to half of the number of logical CPU cores" (Playwright TestConfig, read 2026-11-26).
- Set the worker count in the config or on the command line:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
fullyParallel: true,
workers: process.env.CI ? 2 : undefined,
});
npx playwright test --workers 4
- Decide how fine to split. By default files run in parallel and tests inside a file run in order;
fullyParallel: trueruns every test in every file in parallel. A single file can opt in withtest.describe.configure({ mode: 'parallel' })or stay in order withmode: 'serial', where "If one of the serial tests fails, all subsequent tests are skipped" (Playwright parallelism, read 2026-11-26). - Give each worker its own data.
process.env.TEST_PARALLEL_INDEXruns from 0 to workers minus 1; use it to pick a separate test account or database per worker.
How do I run Python or Selenium tests in parallel on one machine?
Run them in pytest-xdist processes. Playwright's Python guide gives pip install pytest-xdist and pytest --numprocesses auto (Playwright Python test runners, read 2026-11-26). The two counting modes differ: "With -n auto, pytest-xdist will use as many processes as your computer has physical CPU cores", and -n logical uses logical cores instead (pytest-xdist distribution, read 2026-11-26). --dist loadfile keeps a file's tests on one worker, which helps when they share expensive setup.
How many browsers can one machine take?
About one browser per CPU core is the documented ceiling. The defaults of the three tools agree:
Table: Default and documented parallelism per machine
| Tool | Default | Documented guidance |
|---|---|---|
| Playwright Test | Half the logical CPU cores | Playwright recommends workers: 1 on CI "to prioritize stability and reproducibility" (Playwright CI) |
pytest-xdist -n auto | One process per physical core | --maxprocesses caps the count |
| docker-selenium Node | One session per container | Raise up to the processor count; "running more browser sessions than the available processors is not recommended" (docker-selenium) |
Go past this and tests start to time out because pages render late, which looks like flakiness. Our guide to fixing flaky browser tests shows how to tell the two apart.
How do I split a suite across machines?
Split it into shards with --shard=x/y and run one shard per machine. Playwright's example for four machines (Playwright sharding, read 2026-11-26):
npx playwright test --shard=1/4
npx playwright test --shard=2/4
npx playwright test --shard=3/4
npx playwright test --shard=4/4
"Playwright can only shard tests that can be run in parallel", so by default whole files are shared out. With fullyParallel: true tests are split one by one and the shards come out even. We ran a two-test project with fullyParallel: true and --shard=1/2 on @playwright/test 1.65.1 on 26 November 2026, and the first shard ran exactly one of the two tests.
The machines can come from three places, all running the same shard command:
- Promigence sandboxes forked from one snapshot. Promigence's guide to snapshots shows
Sandbox.forkstarting several copies of a prepared sandbox and running a command in each with its own environment variables, in TypeScript or Python (Promigence snapshot and fork guide, read 2026-11-26). The guide's own words: "Every copy starts with the files the sandbox had when you took the snapshot", so a snapshot taken afternpm ciandnpx playwright installhands every shard a ready project, and the shard number goes in as a variable. Its FAQ gives how long a copy takes to start: "A copy takes 39 ms, and a hundred at once still land at 122 ms" (Promigence FAQ, read 2026-11-26), times Promigence measured server-side, not through the network (Promigence SWE-bench page, read 2026-11-26). The quickstart'spromigence run quoteprices the run before anything starts, and--capturns that price into a hard limit (Promigence quickstart, read 2026-11-26). - Your own machines or containers, each running one shard command, for example the official Playwright image in Docker.
- A Selenium Grid, for Selenium suites: tests stay on one machine and send sessions to Nodes on many (Selenium Grid, read 2026-11-26).
A sketch of the first route in TypeScript, using the calls from Promigence's guide; SNAPSHOT_ID is the id of a snapshot that already holds your project with npm ci and the browsers installed:
import { PromigenceClient, Sandbox } from "@promigence/sdk";
const client = new PromigenceClient(); // reads PROMIGENCE_API_KEY
const SHARDS = 4;
const copies = await Sandbox.fork(process.env.SNAPSHOT_ID!, {
client, count: SHARDS, spendCap: 2, timeoutMs: 30 * 60_000,
});
const codes = await Promise.all(
copies.map(async (sbx, i) => {
const r = await sbx.commands.run(
`cd /work/repo && npx playwright test --shard=${i + 1}/${SHARDS}`,
{ timeoutMs: 25 * 60_000, throwOnExit: false },
);
await sbx.kill();
return r.exitCode;
}),
);
process.exit(codes.every((c) => c === 0) ? 0 : 1);
Other hosted services also start many copies from one prepared state, and each states its own start time, timing its own interval (read 2026-11-26):
- AWS: Amazon Bedrock AgentCore Runtime V2 prepares your container once and "restores that snapshot for each new instance", which AWS says "keeps cold starts fast and consistent regardless of concurrency or image size"; the page states no time (AgentCore Runtime documentation). AgentCore Browser, a managed browser your tests can drive, gives each session 1 vCPU and 4 GB (AgentCore quotas).
- Daytona: "any number of new sandboxes can start from the same snapshot" (Daytona snapshots documentation), and its home page gives "Sub 90ms sandbox creation from code to execution" (Daytona home page).
- E2B: "a single snapshot can be used to create many new sandboxes" (E2B snapshots documentation), and its template documentation says snapshots let it "load the sandbox in ~80ms any time later with all the processes already running" (E2B template documentation).
- Google Cloud: Agent Sandbox on GKE assigns each claim a sandbox from a warm pool of pre-warmed ones, which "enables new sandboxes to be created in under a second" (GKE Agent Sandbox documentation), and a Pod snapshot can be the base for "multiple new sandboxes with the same initialized state" (GKE Pod snapshots documentation).
- Modal: a filesystem snapshot is an Image, so "you can create multiple Sandboxes from the same snapshot" (Modal Sandbox snapshots guide), and "Modal Sandboxes start in under one second" (Modal Sandboxes page).
How do I combine the reports from all shards?
Combine them with the blob reporter and merge-reports. Set reporter: process.env.CI ? 'blob' : 'html', copy every shard's blob-report folder into one directory, then run (Playwright sharding, read 2026-11-26):
npx playwright merge-reports --reporter html ./all-blob-reports
The result is one HTML report for the whole suite, as if it had run on a single machine.
What we read for this article
- Promigence snapshot and fork guide, https://www.promigence.ai/docs/guides/snapshot-and-fork, read 2026-11-26
- Promigence quickstart, https://www.promigence.ai/docs/quickstart, read 2026-11-26
- Promigence FAQ, https://www.promigence.ai/faq, read 2026-11-26
- Promigence SWE-bench page, https://www.promigence.ai/for/swe-bench, read 2026-11-26
- Amazon Bedrock AgentCore Runtime documentation and AgentCore quotas, read 2026-11-26
- Daytona snapshots documentation and Daytona home page, read 2026-11-26
- E2B snapshots documentation and E2B template documentation, read 2026-11-26
- GKE Agent Sandbox documentation and GKE Pod snapshots documentation, read 2026-11-26
- Modal Sandbox snapshots guide and Modal Sandboxes page, read 2026-11-26
- Playwright parallelism, read 2026-11-26
- Playwright TestConfig, read 2026-11-26
- Playwright sharding, read 2026-11-26
- Playwright CI, read 2026-11-26
- Playwright Python test runners, read 2026-11-26
- pytest-xdist distribution, read 2026-11-26
- docker-selenium, read 2026-11-26
- Selenium Grid, read 2026-11-26
Q&A
How many Playwright workers should I use?
Start from the default, half the logical CPU cores, and lower it if tests time out under load. Playwright recommends one worker on CI machines for stability and reproducibility; to finish sooner there, shard the suite across machines.
What is the difference between workers and shards in Playwright?
Workers are processes on one machine, each with its own browser. Shards split the test list across separate runs, usually on separate machines; each shard then uses its own workers.
Why are my Playwright shards uneven?
Without fullyParallel, Playwright shards whole files, so one large file lands on one shard. Set fullyParallel true to split by test, or keep files small and similar in size.
How do I run pytest Playwright tests in parallel?
Install pytest-xdist and run pytest --numprocesses auto, which starts one process per physical CPU core. Use -n logical to count logical cores instead.