javascripttypescriptautomated-testsplaywrightparallel-execution

Run some tests in serial mode and some in parallel in the same file Playwright


In this example I have 4 tests in the same spec file, and I want 2 of them to be executed in serial mode and the other 2 to be executed in parallel.

// a,b - to be executed in parallel mode
test("a", async ({}) => console.log("a"));
test("b", async ({}) => console.log("b"));

// c,d - to be executed in serial mode
test("c", async ({}) => console.log("c"));
test("d", async ({}) => console.log("d"));

In my playwright.config file I have the fullyParallel: true setup.

In Playwright docs there is an example of excluding an entire spec file from parallelism by adding this line to the spec file:

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

Is there any way to do that in the same file?


Solution

  • I've found a way to accomplish the desire behavior, by surrounding c & d tests with test.describe and inside it to put the test.describe.configure({ mode: 'parallel' }) line:

    // a,b - executed in parallel mode
    test("a", async ({}) => console.log("a"));
    test("b", async ({}) => console.log("b"));
    
    test.describe("serial executed tests", () => {
      // disables the parallel setting for tests in the parent describe scope
      test.describe.configure({ mode: "serial" });
    
      // c,d - executed in serial mode
      test("c", async ({}) => console.log("c"));
      test("d", async ({}) => console.log("d"));
    });