To run tests in parallel within a single file using @playwright/test, you can utilize the test.describe.configure()
method. This allows you to run independent tests in parallel, but keep in mind that they'll be executed in separate worker processes and cannot share any state or global variables.
First, import test.describe.configure()
from '@playwright/test' and call it with the mode set to 'parallel'. Then, define your tests using the test()
function within the describe
block. Each test will execute all relevant hooks just for itself, including beforeAll
and afterAll
.
import { test, expect } from '@playwright/test';
const parallel = test.describe.configure({ mode: 'parallel' });
parallel.describe('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
});
});
If you want to enable fully-parallel mode for all tests, set fullyParallel: true
in your configuration file or for specific projects only. However, be aware that some features like the VS Code Extension and tracing might not work properly in this mode.
For inter-dependent tests that need to be executed serially, you can use the .serial
modifier on each individual test()
. It's generally recommended to make your tests isolated so they can be run independently.
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].