What are the options for running tests in parallel using Playwright?


Running Tests in Parallel with Playwright

You have a few options to run tests in parallel with Playwright. By default, tests in a single file run in order. But, if you have many independent tests in a single file and want to run them in parallel, you can use the test.describe.configure() method with the mode set to 'parallel'.

test.describe.configure({ mode: 'parallel' })('my suite', () => {
  // your tests here

Remember, parallel tests are executed 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 opt-in all tests into fully-parallel mode by setting fullyParallel: true in the configuration file. This allows Playwright to shard a test suite so it can be executed on multiple machines.

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  use: {
    // Other options...
  projects: [
      name: 'Chrome',
      use: { browserName: 'chromium' },
    // Other projects...
  reporter: [['list'], ['junit', { outputFile: 'junit.xml' }]],
  workers: 5,
  timeout: 60000,
  retries: 1,
  fullyParallel: true

export default config;

When running tests in parallel mode, each worker process is assigned two ids: a unique worker index that starts with 1 and a parallel index that is between 0 and workers • 1. You can read an index from environment variables process.env.TEST_WORKER_INDEX and process.env.TEST_PARALLEL_INDEX or access them through testInfo.workerIndex and testInfo.parallelIndex.

You can control the order of test execution when disabling parallelism by either naming your files alphabetically or using a "test list" file. When disabling parallel execution of tests, Playwright Test runs files alphabetically by default based on their names.

For more details, check out this blog post on maximizing test efficiency with parallelism in Playwright.


Thank you!
Was this helpful?
Still have questions?

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

Related Questions

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.