将 Allure 报告集成到 Playwright 测试 Azure Pipeline 中

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

我正在练习 Playwright 自动化,并学习将其与 Azure 中的 CI/CD 管道集成。 我已经设法在 Azure 中创建一个运行我的 Playwright 代码的存储库和管道,但我在让 Allure 报告正常工作方面有点困难

这是我的azure管道的yaml文件,我在Allure步骤中添加如下:

trigger:
- none

pool: customagent
  

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18'
  displayName: 'Install Node.js'
- script: npm ci
  displayName: 'npm ci'
- script: npx playwright install --with-deps
  displayName: 'Install Playwright browsers'
- script: npm run regression
  displayName: 'Run Playwright tests' 
- script: npx playwright test --reporter=line,allure-playwright
  displayName: 'Use Allure reports'
- script: npm run GenReport
  displayName: 'Generate Allure reports and clean'
- task: qameta.allure-azure-pipelines.PublishAllureReport.PublishAllureReport@1
  inputs:
    testResultsDir: 'allure-results'
    reportName: 'Report'
  env:
    CI: 'true'

这是我的 Playwright package.json 文件中的内容,我添加了自定义脚本:

{
  "name": "playwright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "regression": "npx playwright test",
    "GenReport": "npx allure generate ./allure-results --clean",
    "Open Allure Reports": "allure open ./allure-report"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.43.1",
    "@types/node": "^20.7.1",
    "@zerostep/playwright": "^0.1.5",
    "allure-playwright": "^2.15.1"
  },
  "dependencies": {
    "@cucumber/cucumber": "^10.4.0"
  }
}

当我运行管道时,它最终会打开 html 报告器,然后保持在该步骤。我真的不知道从现在开始该做什么,我已经为 Allure 报告查看器安装了必要的市场扩展,我在 yaml 文件中使用了它

azure-devops playwright allure azure-automation playwright-test
1个回答
0
投票

运行

npx playwright test
时我可以重现相同的问题。

要解决此问题,您可以在管道的根级别添加管道变量:

CI:true

例如:

trigger:
- none

pool: customagent

variables:
  CI: true 

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18'
  displayName: 'Install Node.js'
- script: npm ci
  displayName: 'npm ci'
- script: npx playwright install --with-deps
  displayName: 'Install Playwright browsers'
- script: npm run regression
  displayName: 'Run Playwright tests' 
- script: npx playwright test --reporter=line,allure-playwright
  displayName: 'Use Allure reports'
- script: npm run GenReport
  displayName: 'Generate Allure reports and clean'
- task: qameta.allure-azure-pipelines.PublishAllureReport.PublishAllureReport@1
  inputs:
    testResultsDir: 'allure-results'
    reportName: 'Report'
  env:
    CI: 'true'

或者您可以将环境变量添加到脚本任务中:

例如:

- script: npm run regression
  displayName: 'Run Playwright tests' 
  env:
    CI: true

然后它将继续运行接下来的任务。

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