Rayrun

How do I configure Playwright Test to run tests in parallel?

Answer

Running Tests in Parallel with @playwright/test

To run tests in parallel, you can use the built-in parallelism feature of @playwright/test. By default, tests in a single file are executed sequentially. However, you can enable parallel execution for independent tests within a file using the test.describe.configure() method and setting the mode: 'parallel' option. This runs each test in a separate worker process, without sharing any 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/blog');
    // Your test code here
  });
});

For fully-parallel mode across all files in a project, set fullyParallel: true in your configuration file. This executes all tests concurrently.

Keep in mind that parallel execution doesn't guarantee a specific order of test execution across files. To control the order, consider using a naming convention or a "test list" file.

If you want to disable parallelism and use a single worker, set the workers: 1 option in your configuration file or pass --workers=1 to the command line when running your tests.

In conclusion, @playwright/test makes it easy to run tests in parallel using its built-in features. You can choose between fully-parallel mode or selectively enable it for specific projects. However, controlling execution order across multiple files may require additional steps such as naming conventions or "test list" files.

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.