0

我使用 Azure DevOps 测试计划和测试套件在 YAML 构建管道中执行自动化测试。对于每个版本,我都会使用新的测试套件创建一个新的测试计划。实际上,我手动搜索测试计划和测试套件的 ID,并将它们复制到 YAML 文件中。

- task: VSTest@2
  displayName: 'Run automated UI tests'
  inputs:
   testSelector: testPlan
   testPlan: 585
   testSuite: 586,929,930,680,683,684,685,931,681,686,687,688,767,682,689,690,691,768,692
   testConfiguration: 2
   uiTests: true
   testRunTitle: 'Automated UI testing'

有没有可能自动做到这一点?或者减少手动工作的可能性,例如只需更改管道中的测试计划 ID 并自动包含所有测试套件?

4

3 回答 3

1

有没有可能自动做到这一点?或者减少手动工作的可能性,例如只需更改管道中的测试计划 ID 并自动包含所有测试套件?

您可以通过 Powershell 任务中的脚本获取测试计划的测试套件,然后将获取的结果分配给变量。

使用测试套件 -为计划休息 api 获取测试套件:

GET https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/suites?api-version=6.0-preview.1

示例脚本:

$url = 'https://dev.azure.com/{organization}/{project}/_apis/testplan/Plans/{planId}/suites?api-version=6.0-preview.1';

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"} -Method Get

$testSuites = $response

Write-Host "results = $($testSuites | ConvertTo-Json -Depth 100)"

在 VSTest 任务中:

- task: VSTest@2
  displayName: 'Run automated UI tests'
  inputs:
   testSelector: testPlan
   testPlan: 585
   testSuite: $(testSuites)
   testConfiguration: 2
   uiTests: true
   testRunTitle: 'Automated UI testing'
于 2020-12-21T10:04:01.540 回答
0

YAML 文件位于您的存储库中。因此,您可以通过 REST API 编辑此文件。这是一个示例:更新文件。在这种情况下,您可能有一些 YAML 文件模板,确定测试计划 ID 和测试套件(获取计划的测试套件),然后使用新 ID 更新 YAML 文件。

于 2020-12-03T12:31:33.197 回答
0

这是使用Azure DevOps API于 2022 年 3 月 1 日开始工作的完整解决方案

- pwsh: |
    $organization = "YOUR ORG NAME HERE"
    $project = "YOUR PROJECT NAME HERE"
    $planId = 585
    $password = ConvertTo-SecureString -String $env:SYSTEM_ACCESSTOKEN -AsPlainText -Force

    $url = "https://dev.azure.com/$organization/$project/_apis/test/Plans/$planId/suites?api-version=5.0"
    $cred = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList "AzPipeline", $password

    $response = Invoke-RestMethod -Uri $url -Authentication Basic -Method Get -Credential $cred

    $testSuites = $response |
      ForEach-Object{ $_.value.id} |
      Join-String -Separator ', '

    Write-Host "##vso[task.setvariable variable=testSuites;]$testSuites"
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- task: VSTest@2
  inputs:
    testSelector: testPlan
    testPlan: 585
    testSuite: $(testSuites)
    testConfiguration: 2
    uiTests: true
    testRunTitle: 'Automated UI testing'
于 2022-03-01T18:38:29.630 回答