以串行模式运行一些测试,并在同一个文件中并行运行一些测试 Playwright

问题描述 投票:0回答:1

在此示例中,我在同一个规范文件中有 4 个测试,我希望其中 2 个以串行模式执行,另外 2 个以并行模式执行。

// 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"));

在我的

playwright.config
文件中,我有
fullyParallel: true
设置。

在 Playwright 文档中,有一个示例,通过将此行添加到规范文件中来排除整个规范文件的并行性:

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

有什么办法可以在同一个文件中做到这一点吗?

javascript typescript parallel-processing playwright
1个回答
0
投票

我找到了一种实现愿望行为的方法,通过用

test.describe
包围 c 和 d 测试,并在其中放置
test.describe.configure({ mode: 'parallel' })
行:

// 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"));
});
© www.soinside.com 2019 - 2024. All rights reserved.