Sure, you can control the number of workers at a test level in @playwright/test. It runs tests in parallel by default using multiple worker processes.
To change the number of workers, use the --workers
option in the command line or set the workers
property in the configuration file. Here's how you can do it:
npx playwright test --workers 4
Or in the configuration file:
import { defineConfig } from '@playwright/test';
export default defineConfig({
workers: process.env.CI ? 2 : undefined,
});
If you want to run tests sequentially, set workers: 1
or use --workers=1
in the command line.
Each worker process has two ids: a unique worker index starting from 1 and a parallel index between 0 and workers - 1. You can access these indices from environment variables process.env.TEST_WORKER_INDEX
and process.env.TEST_PARALLEL_INDEX
, or through testInfo.workerIndex
and testInfo.parallelIndex
.
For more details on parallelism in Playwright, check out this blog post.
If you still have questions, please ask a question and I will try to answer it.
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].