[microsoft/playwright][BUG] Playwright的全局拆卸需要超时时间

2024-04-09 568 views
9
系统信息
  • 编剧版本:[v1.36]
  • 操作系统:[全部、Windows 11、Ubuntu 20、macOS 13.2 等]
  • 浏览器:[全部、Chromium、Firefox、WebKit]
  • 其他信息:
源代码
  • [ ] 我提供了准确的源代码,可以在本地重现该问题。看起来全局拆卸大约需要 30 秒,但测试执行需要 1 秒。我从 CLI 工具进行了简单的测试,并将项目添加到配置文件中。需要注意的重要事项:如果我执行 by testMatch =/.*.spec.ts/,则所有工作均按要求进行

    https://github.com/AlexeyCL/Playwright-teardown

链接到带有重现的 GitHub 存储库

[ https://github.com/your_profile/playwright_issue_title ]

或者

配置文件

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';
/**
 * See https://playwright.dev/docs/test-configuration.
 */
const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'test',
      testMatch: '*tests/*.spec.ts',
    },
],
  testMatch: /.*.spec.ts/,

  /* Maximum time one test can run for. */
  timeout: 60 * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 20000,
  },
  /* Run tests in files in parallel */
  fullyParallel: !!process.env.CI,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 0 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 5 : 1,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [['list']],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    channel: process.env.DOCKER ? 'chromium' : 'chrome',
    headless: !!process.env.CI,
    viewport: { width: 1280, height: 720 },
    ignoreHTTPSErrors: true,
    baseURL: 'https://playwright.dev/',
    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: 30000,
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'retain-on-failure',
    video: 'retain-on-failure',

    screenshot: 'only-on-failure',
  },

  /* Folder for test artifacts such as screenshots, videos, traces, etc. */
  outputDir: 'test-results/',
};

export default config;

测试文件(独立)

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

test('has title', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Expect a title "to contain" a substring.
  await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
  await page.goto('https://playwright.dev/');

  // Click the get started link.
  await page.getByRole('link', { name: 'Get started' }).click();

  // Expects the URL to contain intro.
  await expect(page).toHaveURL(/.*intro/);
});

脚步

  • [运行测试] pnpm运行测试
  • [...]

预期的

[描述预期行为]

实际的

[描述实际行为]

回答

1

@AlexeyCL 首先,您位于https://github.com/AlexeyCL/Playwright-teardown的演示项目没有任何全局拆卸。

其次,我运行了测试,它们在我的机器上顺利通过:

图像

那么究竟出了什么问题呢?

2

嗨,我是说剧作家的拆解,我还有一次执行

图像
5

您可以在这里看到测试的执行时间约为 2 秒,其他时间为 31 秒。我想对剧作家进行某种拆解

8

@AlexeyCL 啊,我明白了,但我无法重现这个。

您能否运行此命令并将DEBUG=* npx playwright test所有日志(这将是很多日志!)粘贴到某处? (例如到一个新的 gist.github.com)

9

@aslushnikov 你好,我把 ling 放到了这里的日志文件中,要点有问题

另外,我注意到在这些行之后系统卡住了一段时间(lof 文件的末尾)

01b[30m+153ms\u001b[0m\n"}}} +0ms
  pw:browser [pid=42864] <gracefully close start> +153ms
  pw:test:protocol ◀ RECV {"method":"__dispatch__","params":{"method":"stdErr","params":{"text":"  \u001b[38;5;34;1mpw:protocol \u001b[0m◀ RECV {\"id\":-9999,\"result\":{}} \u001b[38;5;34m+148ms\u001b[0m\n"}}} +0ms
  pw:protocol ◀ RECV {"id":-9999,"result":{}} +148ms
6

@AlexeyCL 看起来关闭浏览器需要很长时间。你有机会使用Windows吗?

您可以尝试在不同的浏览器中运行测试,看看问题是否仍然存在:

npx playwright test --browser firefox
npx playwright test --browser webkit
7

@aslushnikov 好吧,我玩了配置文件并发现,这个问题发生在使用channels像这里这样的情况下

projects: [
    {
      name: 'test',
      testMatch: '*tests/*.spec.ts',
      use: {
        ...devices['Desktop Chrome'],
        channel: 'chrome'
      },
    },
图像

有了这个配置

    {
      name: 'test',
      testMatch: '*tests/*.spec.ts',
      use: {
        ...devices['Desktop Chrome'],
      },
    },
],
图像
4

@AlexeyCL 你可以尝试启动稳定的 chrome 并尝试关闭它吗?我希望它也能挂起来。

6

@aslushnikov 我的 chrome 已更新(版本 115.0.5790.98(官方版本)(arm64))并且运行良好。我还使用另一个框架,并且 Chrome 没有任何问题另外,我发现这个配置

  projects: [
    {
      name: 'test',
      testMatch: '*tests/*.spec.ts',
      use: {
        ...devices['Desktop Chrome '],
        channel: 'chromium'
      },
    },
],

一切顺利,花了 3 秒

6

@AlexeyCL 我明白了。因此,看起来有一些有效的公司政策扰乱了您计算机上 Chrome 的自动化。你是在窗户上吗?在这种情况下,这超出了项目的范围。

3

@aslushnikov 不,我使用 mac。我发现这个解决方法对我来说很有效。如果您告诉我这不是问题,我们将使用解决方法

1

甜的。由于我无法在本地重现此问题,因此让我们采取适合您的解决方法。

7

@aslushnikov 感谢您的快速回复。周末愉快

0

我遇到了同样的问题,关闭时间大约为 32 秒:

  pw:test:task "test suite" finished +0ms
  pw:test:task "teardown for start workers" started +0ms
  pw:test:task "teardown for start workers" finished +0ms
  pw:test:task "teardown for plugin begin" started +0ms
  pw:test:task "teardown for plugin begin" finished +0ms
  pw:test:task "teardown for report begin" started +0ms
  pw:test:task "teardown for report begin" finished +0ms
  pw:test:task "teardown for plugin setup" started +0ms
(...hangs for ~30 sec here...)
  16 passed (33.4s)

测试本身需要大约 1 秒才能运行,然后输出会在上面所示的位置挂起 @aslushnikov - 有什么想法吗?

5

@latkinsa 你能尝试使用@playwright/test@next 看看它是否会让事情变得更好吗?

如果没有,请提交一个单独的问题并提供我们可以在本地运行和调试的重现!

2

谢谢 - Playwright 的 VSCode 插件之间似乎存在一些干扰。干净地重新安装、重新下载浏览器和重新启动 VSCode 似乎有帮助。