To run parallel tests in a single file with Playwright, use the test.describe.configure()
method. This allows you to run independent tests in parallel, but note that they'll be executed in separate worker processes and can't share state or global variables.
Here's an example using test.describe.configure()
with the mode
parameter set to 'parallel'
:
import { test } from '@playwright/test';
test.describe.configure({ mode: 'parallel' });
test('runs in parallel 1', async ({ page }) => {
// ...
});
test('runs in parallel 2', async ({ page }) => {
// ...
});
You can also enable fully-parallel mode for all tests by setting the fullyParallel
option to true
in your configuration file or for specific projects:
// Directly within configuration file
import { defineConfig } from '@playwright/test';
export default defineConfig({
fullyParallel: true,
});
// For specific projects
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
fullyParallel: true,
},
],
});
Remember that when running parallel tests, each test executes all relevant hooks just for itself (including beforeAll
and afterAll
), so they can't share any state or global variables.
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].