为什么剧作家在测试已经通过的情况下还要花额外的时间来完成?

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

示例 1(访问 google.com)

import { test, expect } from "@playwright/test";

test("example", async ({ page }) => {
  await page.goto("https://www.google.com");
});

控制台:

Running 1 test using 1 worker

  ✓  1 [Microsoft] › google.spec.ts:3:6 › example (2.9s)

  1 passed (4.2s)

示例2(访问baidu.com)

import { test, expect } from "@playwright/test";

test("example", async ({ page }) => {
  await page.goto("https://www.baidu.com");
});

控制台:

Running 1 test using 1 worker

  ✓  1 [Microsoft] › baidu.spec.ts:3:6 › example (1.9s)

  1 passed (9.3s)

问题

为什么即使测试通过了,Playwright 仍需要额外的时间来终止?

为什么第二个测试需要约 10 秒才能完成?

配置

回购:https://github.com/kingyue737/playwright-test

我在带有内置 Edge 的 Windows 10/11 上运行它们。 Playwright版本是^1.39.0.

import type { PlaywrightTestConfig } from "@playwright/test";
import { devices } from "@playwright/test";

const config: PlaywrightTestConfig = {
  testDir: "./e2e",
  timeout: 30 * 1000,
  expect: {
    timeout: 5000,
  },
  use: {
    actionTimeout: 0,
    headless: false,
  },
  projects: [
    {
      name: "Microsoft",
      use: {
        ...devices["Desktop Edge"],
        channel: "msedge",
      },
    },
  ],
};

export default config;
e2e-testing playwright
1个回答
0
投票

抱歉这么晚才回复您,但我可以为您解答。

由于剧作家

await page.goto()
方法的工作原理,您的虚拟测试显示不同的时间。

这个方法显然是异步的,并且将导航到提供的 URL。但是,它也会等待打开时触发的加载状态完成。

即使使用相同的 URL,测试中的时间也可能永远不会相同,因为等待的加载事件包括可能运行的脚本、图像加载、样式等。

如果没有这种方法的额外好处,导航确实会变得非常不稳定。

无论如何,希望这有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.