Playwright 测试在 Azure Devops Pipeline 上失败并且管道挂起

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

我在 Azure Devops 中创建了一个简单的管道来运行 Playwright 测试,并显式编码了 2 个测试之一以失败。当这种情况在管道执行期间发生时,管道似乎挂起,我猜测最终会超时(30 分钟后,我取消了)。但是,当我执行成功的测试时,管道会成功退出。下面是我的 yaml 管道。有谁知道为什么会发生这种情况 - 我在这里错过了什么吗?

[编辑]:我将下面的行添加到我的 playwright.config.ts 文件中,任务现在像我预期的那样失败了。默认的 Playwright 配置会打开有关任何失败的 html 报告。您可以在 Playwright 中使用很多记者,所以看看什么适合您 (https://playwright.dev/docs/test-reporters)。

记者:[ ['html', { open: '从不' }] ],

trigger:
   - master
   - test
   - dev

pool:
   vmImage: macos-latest

jobs:
   - job: Build
     displayName: Build stage
     steps:
        - task: NodeTool@0
          inputs:
             versionSpec: '16.x'
          displayName: 'Install Node.js'
        - script: |
                npm ci
          displayName: 'Install dependencies'
        - script: |
            npx playwright install --with-deps
          displayName: 'Install Playwright'
        - script: |
            npm run test-unit-smoke
          displayName: 'Run unit tests'

azure-devops continuous-integration automated-tests playwright azure-pipelines-yaml
3个回答
0
投票

原因是您运行测试时虚拟服务器中的“CI”环境变量不正确。如果 CI 目前确实为真,您将永远不会在管道日志中看到“Serving HTML report..”文本。

我在网上读到 CI 提供商默认情况下应该将 CI 设置为 true,但至少在 Azure Pipelines 中我总是必须手动将值设置为 true。

我还没有尝试过 macOS,但对于 Windows,我必须在 YML 文件中运行测试之前添加“set CI=true”。

使用 Windows VM 的 Azure Pipelines 示例:

- task: CmdLine@2
  displayName: 'Run all tests with Chrome and Firefox'
  inputs:
    script: 'set CI=true && npx playwright test ./tests/test.spec.ts --project=chromium --project=firefox'

对于 macOS,您可以在测试前尝试“export CI=true”。


0
投票

2种方式:

  1. 在 playwright.config.ts 中 使用 open: 'never' 扩展记者配置:

reporter: [['html', { outputFolder: 'my-report', open: 'never' }]],

  1. 在 yml 文件中使用以下命令扩展运行脚本: env: CI:true :

- script: |
npx playwright test
      displayName: 'Run Playwright tests'
      continueOnError: true
      env:
        CI: true


0
投票

根据 Playwright 文档Playwright 开发人员在 Playwright repo 上的回答,您应该配置一个环境变量

CI
,其值为
true
1

        - script: |
            npm run test-unit-smoke
          displayName: 'Run unit tests'
          env:
            CI: 'true'

请注意以上答案是首选,因为

CI: 'true'
效果 更多配置,例如
workers
forbidOnly
retries

或者,您可以在

reporter
中设置
playwright.config
属性,如下所示:

reporter: [ ['html', { open: 'never' }] ],
© www.soinside.com 2019 - 2024. All rights reserved.