Playwright Masters

Playwright Parallel Testing: A Complete Guide With Examples

Playwright parallel testing allows automation testers to run multiple independent tests simultaneously instead of executing every test one after another. It helps reduce test execution time, accelerate regression testing, and provide faster feedback during software development.

Playwright Test supports parallel execution through worker processes, the fullyParallel configuration option, parallel test groups, and test sharding.

For example, a test suite with 100 independent tests can run them across multiple workers to complete testing faster. The actual execution time depends on the number of workers, test duration, available computer resources, and application performance.

Table of Contents

In this guide, you will learn how Playwright parallel testing works, how to configure workers, how to run tests in parallel within a file, how to distribute tests across CI/CD jobs, and how to troubleshoot common problems.

The examples use Playwright Test with TypeScript and are intended for beginners and experienced automation testers.

For learners who want to develop practical automation testing skills, PlaywrightMasters provides Playwright training resources to help them understand automation testing concepts and real-world applications.

Playwright Parallel Testing Guide

What Is Playwright Parallel Testing?

Playwright parallel testing is a testing technique that runs multiple automated tests simultaneously using different workers to reduce execution time and deliver faster test results. Instead of running every test one after another, Playwright distributes eligible tests across available workers, helping developers and testers validate web applications more efficiently. For example, a test suite containing 100 independent tests can run multiple tests concurrently rather than waiting for each test to finish before starting the next one.

Instead of waiting for one test to finish before starting another, Playwright can assign independent tests to different worker processes.

Consider an e-commerce website with these automated tests:

  • Test 1 checks whether users can log in.
  • Test 2 checks whether the product search works.
  • Test 3 checks whether product details appear correctly.
  • Test 4 checks whether users can add products to a cart.

When these tests are independent, Playwright can execute them concurrently using multiple workers.

This approach is particularly useful when an application has hundreds or thousands of automated test cases.

However, parallel testing does not guarantee faster execution in every situation. Tests that share data, depend on execution order, or consume excessive system resources may become unreliable or slower when run concurrently.

The main goal of parallel testing is to execute independent tests efficiently while maintaining reliable results.

Why Is Parallel Testing Important in Automation Testing?

Parallel testing is important because modern applications require frequent testing across different features, browsers, and environments.

Running a large regression test suite one test at a time can delay feedback and slow down software releases.

Parallel execution helps address this problem in several ways.

  1. Reduces test execution time

Multiple tests can progress simultaneously, potentially shortening the time required to complete a test suite.

  1. Provides faster feedback

Developers can discover failed tests sooner and investigate problems before releasing new application changes.

  1. Improves regression testing efficiency

Regression testing checks whether existing features continue working after code changes. Parallel execution makes frequent regression testing more practical for large applications.

  1. Supports CI/CD automation

Continuous integration pipelines can run automated tests whenever code changes are submitted, helping teams detect problems earlier.

  1. Improves browser coverage

Playwright projects can test applications across Chromium, Firefox, and WebKit, helping teams identify browser-specific issues.

These benefits depend on test independence, available resources, and appropriate configuration.

How Does Playwright Parallel Execution Work?

Playwright Test uses worker processes to execute tests.

A worker is an operating-system process that runs tests and manages its own browser instance.

Playwright Test runs multiple automated tests at the same time by distributing them across separate worker processes.Tests inside the same file normally execute sequentially unless you configure additional parallelism.

Imagine your project contains these files:

tests/

├── login.spec.ts

├── homepage.spec.ts

├── search.spec.ts

└── checkout.spec.ts

Playwright can distribute these files across available workers.

For example, one worker might execute the login tests while another handles the homepage tests. Additional workers can execute search and checkout tests.

The actual scheduling depends on the available tests, worker limit, and execution configuration.

What Is a Worker in Playwright?

A worker in Playwright is a separate operating system process that executes automated tests independently. Playwright Test uses worker processes to run multiple tests in parallel, helping reduce the overall test execution time. Each worker has its own browser instance and test environment, allowing tests to run separately without interfering with one another.

For example:

import { defineConfig } from ‘@playwright/test’;

 

export default defineConfig({

  workers: 4,

});

 

This setting enables Playwright to run tests using a maximum of four worker processes simultaneously.

To run tests using two workers, execute:

npx playwright test –workers=2

 

To run tests using a single worker, execute:

npx playwright test –workers=1

 

Using one worker can help you investigate failures that occur only during parallel execution.

Remember that four workers do not guarantee a fourfold improvement in speed. The application, test suite, CPU, memory, and browser workload all affect performance.

How to Enable Playwright Parallel Testing

You can begin parallel testing in an existing Playwright Test project.

Step 1: Install Playwright

If you do not have a Playwright project, create one using:

npm init playwright@latest

 

Follow the prompts to complete the installation.

If you already have a project, make sure the Playwright Test package is installed.

Step 2: Create a Test File

Create a file named parallel.spec.ts inside your test directory.

Add the following example:

import { test, expect } from ‘@playwright/test’;

 

test(‘homepage displays the correct title’, async ({ page }) => {

  await page.goto(‘https://playwright.dev/’);

 

  await expect(page).toHaveTitle(/Playwright/);

});

 

test(‘getting started link is visible’, async ({ page }) => {

  await page.goto(‘https://playwright.dev/’);

 

  await expect(

    page.getByRole(‘link’, { name: ‘Get started’ })

  ).toBeVisible();

});

 

test(‘documentation page can be opened’, async ({ page }) => {

  await page.goto(‘https://playwright.dev/’);

 

  await page.getByRole(‘link’, { name: ‘Get started’ }).click();

 

  await expect(page).toHaveURL(/intro/);

});

 

These examples demonstrate independent checks against the Playwright website. They assume the relevant links and page structure remain available.

Each test uses the page fixture to access a browser page where it can perform actions and verify application behavior.

Step 3: Execute the Tests

Run the following command:

npx playwright test

 

Playwright schedules and runs tests based on the number of workers configured in the test settings.

 

To specify four workers, run:

npx playwright test –workers=4

 

To run only the test file created above, use:

npx playwright test tests/parallel.spec.ts –workers=4

 

You can also open the HTML report after execution:

npx playwright show-report

 

The report helps you inspect passed tests, failed tests, execution details, and other available debugging information.

How to Configure Workers in playwright.config.ts

The playwright.config.ts file controls important settings for a Playwright project, including test directories, worker limits, retries, reporters, and browser projects.

Consider this configuration:

import { defineConfig } from ‘@playwright/test’;

 

export default defineConfig({

  testDir: ‘./tests’,

 

  workers: process.env.CI ? 2 : undefined,

 

  retries: process.env.CI ? 2 : 0,

 

  reporter: ‘html’,

});

 

Here is what each setting means:

  • testDir identifies the directory containing your tests.
  • workers limits execution to two workers when the CI environment variable is set.
  • retries allows failed tests to be retried in CI.
  • reporter generates an HTML test report.

When workers is undefined, Playwright chooses its default worker count.

The example provides a conservative starting point for CI environments, but it is not a universal recommendation. The best worker limit depends on available CPU, memory, and application capacity.

Retries should help collect diagnostic evidence, not conceal unstable tests. Investigate repeated failures even when a retry passes.

What Is fullyParallel in Playwright?

The fullyParallel option allows Playwright to schedule individual tests in parallel, including tests within the same file.

For example:

import { defineConfig } from ‘@playwright/test’;

 

export default defineConfig({

  fullyParallel: true,

  workers: 4,

});

 

With fullyParallel: true, independent tests can be distributed across workers more flexibly.

By default, Playwright runs test files in parallel, while tests within the same file usually execute one after another.

When Should You Use fullyParallel?

Use fullyParallel: true when your test suite contains independent test cases and you want to improve scheduling flexibility.

It can be particularly useful when a small number of files contain many tests.

Before enabling it, check whether your tests depend on shared accounts, database records, files, or previously executed tests.

For example, suppose one test creates a user account and another test expects that account to exist.

If both tests run independently, the second test might start before the account has been created.

The solution is to make each test responsible for preparing the state it needs.

Parallel execution works best when every test can run independently of other tests.

How to Run Tests in Parallel Within One File

You can configure a specific group of tests to run in parallel using test.describe.configure().

For example:

import { test, expect } from ‘@playwright/test’;

 

test.describe(‘Homepage tests’, () => {

  test.describe.configure({ mode: ‘parallel’ });

 

  test(‘homepage title is correct’, async ({ page }) => {

    await page.goto(‘https://playwright.dev/’);

 

    await expect(page).toHaveTitle(/Playwright/);

  });

 

  test(‘getting started link is visible’, async ({ page }) => {

    await page.goto(‘https://playwright.dev/’);

 

    await expect(

      page.getByRole(‘link’, { name: ‘Get started’ })

    ).toBeVisible();

  });

});

 

The mode: ‘parallel’ configuration allows tests in this group to execute independently.

Each test should navigate to the website and perform its own assertions rather than relying on another test’s browser state.

This method is useful when you want to introduce parallel execution gradually instead of changing the behavior of your entire project.

Workers vs fullyParallel vs Sharding: What Is the Difference?

These features are related, but they solve different execution problems.

Feature

Purpose

Best use case

Default parallel execution

Runs separate test files concurrently when workers are available

Projects containing multiple test files

workers

Sets the maximum number of worker processes

Controlling concurrency and resource consumption

fullyParallel

Allows individual tests to be scheduled in parallel

Large numbers of independent test cases

test.describe.configure({ mode: ‘parallel’ })

Enables parallel execution for a selected test group

Introducing parallelism selectively

Sharding

Divides the test suite into separate groups

Distributing tests across CI jobs or machines

For example, a small project may need only a few workers.

A large project containing thousands of tests might benefit from both workers and sharding.

The right approach depends on where the execution bottleneck occurs.

What Is Playwright Sharding?

Playwright sharding divides a test suite into smaller groups that can run in separate CI jobs or machines.

Workers provide concurrency within a machine. Sharding distributes the workload across separate execution jobs.

Suppose your test suite takes too long to complete on one CI machine.

You can divide it into four shards.

Run the following commands in separate CI jobs:

npx playwright test –shard=1/4

 

npx playwright test –shard=2/4

 

npx playwright test –shard=3/4

 

npx playwright test –shard=4/4

 

Each command runs a different portion of the test suite.

Important: Sharding reduces the overall pipeline duration only when the shards execute concurrently. Running all four commands sequentially on the same machine does not provide the same benefit.

When fullyParallel is enabled, Playwright can distribute individual tests across shards more flexibly. Without it, sharding generally distributes test files.

When Should You Use Sharding Instead of More Workers?

Use additional workers when one machine has enough spare resources to execute more tests concurrently.

Consider sharding when one machine is already close to its practical resource limit or when you want multiple CI jobs to process the test suite independently.

You can combine sharding and workers. For example, each shard can run multiple workers.

However, this increases resource consumption and may increase infrastructure costs.

Measure execution time, failure rate, and resource usage before deciding how much parallelism your project needs.

How to Run Playwright Tests in Parallel Across Browsers

Modern web applications should work correctly across different browsers.

Playwright supports Chromium, Firefox, and WebKit through browser projects.

Add the following configuration to your playwright.config.ts file:

import { defineConfig, devices } from ‘@playwright/test’;

 

export default defineConfig({

  projects: [

    {

      name: ‘chromium’,

      use: { …devices[‘Desktop Chrome’] },

    },

    {

      name: ‘firefox’,

      use: { …devices[‘Desktop Firefox’] },

    },

    {

      name: ‘webkit’,

      use: { …devices[‘Desktop Safari’] },

    },

  ],

 

  workers: 3,

});

 

This configuration defines three browser projects.

Playwright can schedule tests across the configured projects while respecting the worker limit and available resources.

For example, a homepage test may execute in Chromium, Firefox, and WebKit.

This helps identify browser-specific problems involving page rendering, forms, navigation, or other browser behavior.

However, browser projects do not guarantee that every browser runs simultaneously throughout the entire test suite.

If your application needs to be tested across many browser and operating-system combinations, a cloud testing platform can provide additional execution environments.

How to Run Playwright Parallel Tests in GitHub Actions

GitHub Actions allows teams to automate Playwright tests whenever code changes are submitted.

You can use a CI workflow to install dependencies, install browser binaries, and execute tests.

Create a workflow file at .github/workflows/playwright.yml.

name: Playwright Tests

 

on:

  push:

  pull_request:

 

jobs:

  test:

    timeout-minutes: 30

    runs-on: ubuntu-latest

 

    steps:

      – name: Checkout repository

        uses: actions/checkout@v4

 

      – name: Set up Node.js

        uses: actions/setup-node@v4

        with:

          node-version: 22

          cache: npm

 

      – name: Install dependencies

        run: npm ci

 

      – name: Install Playwright browsers

        run: npx playwright install –with-deps

 

      – name: Run Playwright tests

        run: npx playwright test –workers=2

 

      – name: Upload Playwright report

        if: ${{ !cancelled() }}

        uses: actions/upload-artifact@v4

        with:

          name: playwright-report

          path: playwright-report/

          retention-days: 7

 

This example assumes your repository contains a valid package-lock.json and a Playwright project with the appropriate test scripts and configuration.

The workflow performs five main tasks:

  1. Downloads your repository.
  2. Sets up Node.js.
  3. Installs the project dependencies.
  4. Installs the required Playwright browsers.
  5. Runs tests with up to two workers and uploads the report.

The Node.js version shown is an example. Choose a version supported by your project and dependencies.

For a large test suite, you can extend this workflow with a matrix strategy to execute multiple shards concurrently.

Start with a working single-job workflow before introducing sharding. This makes configuration errors easier to identify.

How to Measure Whether Parallel Testing Improves Performance

Parallel testing should be measured rather than judged by worker count alone.

For a meaningful comparison, run the same test suite under different worker configurations.

Record these measurements:

Measurement

Why it matters

Total execution time

Shows how long the complete test run takes

Test failure rate

Helps identify reliability problems

Retry count

Reveals potentially unstable tests

CPU usage

Indicates whether the machine is overloaded

Memory usage

Helps identify browser resource pressure

CI pipeline duration

Measures the practical impact on delivery workflows

For example, compare runs using one, two, and four workers.

Keep the test suite, browser configuration, environment, and test data consistent.

Repeat the runs where practical to reduce the effect of temporary network or environment differences.

Do not assume that four workers will always outperform two workers. If browser processes compete for limited resources, increasing concurrency can make tests slower.

A useful benchmark should report actual measured results, the machine configuration, and any important limitations.

Best Practices for Reliable Playwright Parallel Testing

1. Make Tests Independent

Each test should prepare its own starting state.

Avoid relying on a previous test to create a record, complete a login, or change a setting.

Independent tests are easier to run concurrently and easier to debug.

2. Use Unique Test Data

Two tests should not unexpectedly modify the same user account or database record.

For example, if two tests change the email address of one account, their results may depend on which update happens last.

Use separate test accounts or uniquely identified records whenever possible.

3. Avoid Shared Mutable Files

Parallel tests can interfere with one another if they write to the same file.

Give each test a unique filename and remove temporary resources once the test execution is complete.

4. Choose Workers Based on Available Resources

More workers consume more CPU and memory.

Begin with a conservative configuration, measure performance, and increase concurrency only when the environment can support it.

5. Investigate Flaky Tests

A flaky test passes sometimes and fails other times without a relevant change to the application.

Parallel execution can expose timing assumptions, shared-state problems, and resource contention.

Use Playwright traces and test reports to investigate failures rather than simply increasing timeouts.

6. Use Fixtures for Reusable Setup

Fixtures help organize test setup, test dependencies, and cleanup.

Use them to create the resources that a test needs while maintaining appropriate isolation.

7. Keep Browser Contexts Isolated

Playwright provides isolated browser contexts through its standard fixtures.

However, browser isolation does not automatically isolate server-side accounts, database records, or external services.

Design both browser state and application data to avoid conflicts.

Common Playwright Parallel Testing Problems and Solutions

Why Do Tests Pass Individually but Fail in Parallel?

Cause: Tests may share an account, modify the same data, or depend on another test’s execution order.

Solution: Make tests independent, create unique test data, and remove hidden dependencies between test cases.

Why Does Increasing Workers Make Tests Slower?

Cause: The computer or CI runner may not have enough CPU or memory to support additional browser processes.

Solution: Reduce the worker count, monitor resource usage, and compare execution times under consistent conditions.

Why Do Tests Fail Because of Execution Order?

Cause: A test may expect another test to create a user, update a setting, or finish a workflow first.

Solution: Prepare the required state independently in each test.

Why Is the Test Suite Still Slow?

Cause: Slow tests, inefficient setup, external service delays, or an overloaded execution environment may be limiting performance.

Solution: Identify the slowest tests, remove unnecessary waits, improve test setup, and consider sharding when additional workers no longer help.

Why Do Login Tests Interfere With Each Other?

Cause: Multiple tests may modify the same server-side account or session.

Solution: Use independent accounts or isolated test data. Separate browser contexts alone cannot prevent conflicts involving shared backend records.

Frequently Asked Questions About Playwright Parallel Testing

1. Does Playwright support parallel testing by default?

Yes. Playwright Test runs different test files in parallel by default when multiple workers are available. Tests within the same file normally run sequentially unless parallel execution is configured.

2. How do I run Playwright tests in parallel?

Run npx playwright test to use the default configuration. To set a worker limit, use npx playwright test –workers=4.

3. What is the difference between workers and sharding in Playwright?

Workers execute tests concurrently within a machine. Sharding divides a test suite into groups that can run in separate CI jobs or machines.

4. What does fullyParallel do in Playwright?

The fullyParallel: true configuration allows individual tests to be scheduled in parallel, including tests within the same file.

5. How many workers should I use in Playwright?

There is no universal best number. Choose a worker limit based on available CPU, memory, browser workload, test-environment capacity, and the number of independent tests.

6. Can Playwright execute tests across multiple browsers?

Yes. Playwright supports Chromium, Firefox, and WebKit. You can define separate browser projects and allow Playwright to schedule tests across them.

7. Does parallel testing guarantee faster execution?

No. Parallel execution can reduce test duration, but the result depends on available resources, test independence, application performance, and execution overhead.

8. Why do Playwright tests fail only during parallel execution?

Common causes include shared test data, execution-order dependencies, file conflicts, timing assumptions, and resource limitations.

9. Can I use parallel testing in CI/CD?

Yes. Playwright tests can run in CI/CD pipelines such as GitHub Actions. You can configure workers within a job or use sharding to distribute tests across multiple jobs.

10. Should beginners learn parallel testing first?

Beginners should first understand locators, assertions, navigation, test structure, and fixtures. After writing reliable tests, they can learn worker configuration, parallel execution, and sharding.

Conclusion: Run Playwright Tests Faster and More Reliably

Playwright parallel testing allows independent automated tests to execute simultaneously, helping teams reduce feedback time and run larger regression suites more efficiently.

Workers control concurrency within a machine, fullyParallel enables more flexible scheduling of individual tests, and sharding distributes the workload across separate execution jobs.

However, increasing concurrency is not the only requirement for successful parallel testing.

Reliable automation also requires independent tests, unique test data, appropriate worker limits, effective debugging, and regular performance measurement.

Start with a small test suite, compare execution times under different worker configurations, and expand parallelism only when your results remain stable.

If you want to develop your automation testing skills, explore the Playwright training resources available through PlaywrightMasters. Learn related concepts through our tutorials on Playwright fixtures, debugging, assertions, API testing, and the Playwright learning roadmap.

Understanding these concepts together will help you build maintainable automation suites and prepare for practical software testing projects.

Playwright Masters automation testing logo - White Back ground

Playwright Masters Team

Playwright Automation Testing Experts | Industry-Focused Training & Practical Learning

Playwright Masters is a dedicated automation testing training platform focused on helping learners build practical skills in Playwright automation testing. Our training covers real-world automation concepts, framework practices, coding, debugging, API testing, cross-browser testing, CI/CD, and interview preparation to help learners develop job-ready testing skills.

Scroll to Top

Start Your Playwright Automation Career Today

Get FREE Demo + Syllabus & Become Job-Ready in Playwright.