What is the process to execute Playwright tests concurrently?


To run @playwright/test tests in parallel, you have several options. By default, tests in a single file run in order. If you want to run independent tests in parallel, use the test.describe.configure() method with the mode set to 'parallel'. Keep in mind that parallel tests run in separate worker processes and can't share any state or global variables. Each test executes all relevant hooks just for itself, including beforeAll and afterAll.

You can also enable fully-parallel mode for all tests by setting fullyParallel: true in the playwright.config.ts file. To enable fully-parallel mode for specific projects, specify it under the projects array.

Each worker process has a unique worker index starting with 1 and a parallel index between 0 and workers - 1. When a worker restarts, the new worker process has the same parallelIndex but a new workerIndex. Access these indices through testInfo.workerIndex and testInfo.parallelIndex.

If you disable parallelism, tests run in alphabetical order. To control test order, name your files alphabetically or use a "test list" file (though this is discouraged).

To shard your test suite across multiple machines, use Playwright's built-in sharding feature. For example, npx playwright test --shard=1/3 divides your suite into three parts, and each part executes one of the three shards specified as arguments (in this case, shard number one).

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.