Rayrun

What are the different ways to run Playwright tests in parallel?

Answer

To run tests in parallel with @playwright/test, you can use several methods:

Option 1: Configure parallel mode for a test suite

Use test.describe.configure() with the mode set to 'parallel'. This runs independent tests in a single file in parallel. Keep in mind that parallel tests run in separate worker processes and cannot share state or global variables.

import { test } from '@playwright/test';

test.describe.configure({ mode: 'parallel' })('Parallel tests', () => {
  test('Test 1', async ({ page }) => {
    await page.goto('https://ray.run/');
    // Your test code here
  });

  test('Test 2', async ({ page }) => {
    await page.goto('https://ray.run/');
    // Your test code here
  });
});

Option 2: Enable fully-parallel mode

Set fullyParallel: true in the configuration file to allow Playwright to shard a test suite for execution on multiple machines.

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

const config: PlaywrightTestConfig = {
  use: { browserName: 'chromium' },
  fullyParallel: true,
};

export default config;

Option 3: Disable parallelism

Set workers: 1 in the configuration file or pass --workers=1 to the command line to disable parallelism and run tests sequentially.

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

const config: PlaywrightTestConfig = {
  use: { browserName: 'chromium' },
  workers: 1,
};

export default config;
npx playwright test --workers=1

Remember that when running multiple test files simultaneously without disabling parallelism, the order of execution across files is not guaranteed. However, disabling parallelism runs files alphabetically by default, allowing some control over execution order.

Thank you!
Was this helpful?
Still have questions?

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

TwitterGitHubLinkedIn
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.