Rayrun

How do I determine the optimal number of workers for my machine when using Playwright Test?

Answer

To determine the optimal number of workers for your machine when using @playwright/test, you'll need to experiment with different values and observe performance metrics such as execution time and resource utilization. The number of workers depends on factors like CPU cores and available memory.

By default, @playwright/test runs test files in parallel, using multiple worker processes. You can control the number of workers via the command line or configuration file. For example, to set the number of workers to 4, you can use the following command:

npx playwright test --workers=4

Or, in your playwright.config.ts file:

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

const config: PlaywrightTestConfig = {
  workers: 4,
  // other configurations...
};

export default config;

Keep in mind that each worker process runs independently and starts its own browser instance. Workers are reused as much as possible to make testing faster, and they are always shut down after a test failure to guarantee a pristine environment for following tests.

To disable parallelism, you can set the number of workers to 1:

const config: PlaywrightTestConfig = {
  workers: 1,
  // other configurations...
};

You can also opt-in to fully-parallel mode for all tests or specific projects using the fullyParallel option in the configuration file.

Remember, there is no fixed limit on the maximum number of workers, so it's essential to experiment and find the best value for your machine. For more insights on maximizing test efficiency with parallelism in Playwright, check out this blog post.

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.