Rayrun

How do I run Playwright tests in a combination of serial and parallel modes?

Answer

Running Playwright Tests in Serial and Parallel Modes

To run Playwright tests in a mix of serial and parallel modes, use the test.describe.configure() method. Set the mode option to 'parallel' to run tests concurrently. If you want all tests to run in parallel, set the fullyParallel: true option globally or for specific projects.

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
  });
});

For tests that need to run serially, use the test.describe.serial.only() method. This creates a focused group of tests that run in serial mode. If a serial test fails, subsequent tests are skipped, and all retries happen together for all failed serial groups.

test.describe.serial.only('Serial tests', () => {
  test('Test 3', async ({ page }) => {
    await page.goto('https://ray.run/');
    // Your test code here
  });

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

However, it's better to make your tests isolated so they can run independently without dependencies on other test cases or suites. Using serial mode is not recommended unless absolutely necessary. By combining test.describe.configure() with 'parallel' or 'fullyParallel: true' options and selectively choosing serial groups, you can execute Playwright tests with different modes based on their requirements.

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 [email protected].