Rayrun
โ† Back to Discord Forum

Running playwright in parallel against multiple backends

hello guys,

does anyone have experience with running playwright tests, against multiple backends? Our tests needs to have clear environment each time its being run. We do that by clearing and setting environment over test api. But when running tests in parallel, we need more running backends. Is there a way to run playwright tests in parallel against multiple backends?

This thread is trying to answer question "Is there a way to run playwright tests in parallel against multiple backends?"

6 replies

Depends on what you mean by backend and environment. You can get index of the worker using test.info().parallelIndex. How you use it is up to you. You can elaborate more if you want more specific ideas.

Certainly! The concept revolves around frontend (FE) and backend (BE) environments. I've established identical environments five times, each running on localhost with different ports (e.g., localhost:3000 to localhost:3005).

My objective is to execute playwright tests on all these instances concurrently, regardless of the order. As soon as one test concludes, another should initiate, ensuring that each test runs only once. Thus, if I initiate a test on machine one, it should not be repeated on any other machine.

In that case, parallelIndex is the thing you're looking for.

const i = test.info().parallelIndex;
await page.goto(`http://localhost:${3000 + i}`;

3000..3005 will be 6 env ๐Ÿ™‚

yeah, you right! ๐Ÿ˜„

thanks, for the info! ๐Ÿ™‚

Answer

Sure, you can run your Playwright tests in parallel against multiple backends. This can speed up your test execution time.

To do this, use the test.describe.configure() function. Set the mode to "parallel". This will run tests within a single file concurrently. Here's how to do it:

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

test.describe.configure({ mode: 'parallel' });

test('runs in parallel 1', async ({ page }) => {
  // Test logic...
});

test('runs in parallel 2', async ({ page }) => {
  // Test logic...
});

In this example, runs in parallel 1 and runs in parallel 2 will run at the same time. Each test will run all relevant hooks like beforeAll and afterAll independently.

If you want to run all your tests or specific projects in parallel, modify the configuration file (playwright.config.ts). Here's how:

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

export default defineConfig({
  fullyParallel: true,
});

This will run all tests across different files or projects at the same time. But remember, each test runs in its own worker process and can't share any state or global variables. So, make sure your tests are isolated and independent.

For more tips on efficient test execution, check out Maximizing Test Efficiency with Parallelism in Playwright.

Related Discord Threads

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.