Rayrun

What is the process to run tests in parallel using Playwright?

Answer

Sure, you can run the same tests multiple times in parallel with Playwright. Here's how:

Single Worker

You can set workers: 1 in the config file or use --workers=1 in the command line. This runs tests sequentially, with only one worker active at a time.

// playwright.config.ts
module.exports = {
  workers: 1
};

Parallel Tests

For independent tests in a single file, use test.describe.configure(). Set mode: 'parallel' to run all tests in the suite in separate worker processes.

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

Fully-Parallel Mode

In playwright.config.ts, set fullyParallel: true for all test files or specific projects. Be mindful of inter-dependent tests that need to run serially. Annotate these as "serial". If a serial test fails, all subsequent tests are skipped.

// playwright.config.ts
module.exports = {
  projects: [
    {
      name: 'Project 1',
      fullyParallel: true
    },
    {
      name: 'Project 2',
      fullyParallel: false
    }
  ]
};

Control Test Execution Order

When not using parallelism, Playwright runs test files alphabetically. You can control the order by prefixing filenames with numbers. Alternatively, define tests in helper functions across multiple files. Call these functions in a specific order to control execution. However, this method is discouraged and supported as a best-effort only.

For more details, check out Maximizing Test Efficiency with Parallelism in Playwright.

References

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 Discord Threads

Related Questions

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.