Playwright v1.50.5发布了
Playwright v1.50.0 引入了多项值得关注的功能和改进,旨在提升测试体验。以下是这些新增功能的详细概述,并附有示例以说明其使用方法。
Runner 增强
1. 步骤超时配置
现在可以通过 timeout 选项为单个测试步骤指定最大运行时间。如果某个步骤的运行时间超过此限制,测试将失败。
示例:
test("example test", async ({ page }) => {
await test.step(
"step with timeout",
async () => {
// 此步骤必须在 1000 毫秒内完成
await page.click("#some-button");
},
{ timeout: 1000 }
);
});
2. 跳过测试步骤
新增的test.step.skip()
方法允许跳过特定的测试步骤,这在某些条件未满足或功能尚未实现的情况下非常有用。
示例:
test("some test", async ({ page }) => {
await test.step("before running step", async () => {
// 正常步骤
});
await test.step.skip("not yet ready", async () => {
// 此步骤将被跳过
});
await test.step("after running step", async () => {
// 即使上一步被跳过,此步骤仍会运行
});
});
3. ARIA 快照存储于单独文件
expect(locator).toMatchAriaSnapshot()
方法已扩展,允许将 ARIA 快照存储在单独的 YAML 文件中,便于更好地组织和版本控制。
示例:
test("ARIA snapshot test", async ({ page }) => {
await page.goto("https://example.com");
await expect(page.locator("body")).toMatchAriaSnapshot();
});
在此示例中,ARIA 快照将存储在对应的 YAML 文件中。