是否可以自动化测试用例(在手动模式下)以在 Bug 解决后再次启动它们?

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

我们在 Azure DevOps 中创建手动测试用例。

在测试点执行过程中,您可以直接创建错误单,该错误单也链接到测试用例。此外,在“执行”选项卡中,测试点的结果从“有效”更改为“错误”。

如果错误单现已处理并收到状态“已解决”,则测试点不会发生任何情况,并且仍处于“错误”状态。有没有办法自动将此测试点设置回“活动”并再次测试?到目前为止,我们总是进入重置状态。

我们使用 Google 和文档来查找信息,了解是否可能以及如何实现。

azure-devops
1个回答
0
投票

no内置功能,可在解决链接的错误时自动将测试点的状态从

Error
重置为
Active
。需要手动将测试点的状态重置为“Active”以重新测试。

但是,您可以使用 REST API 来部分自动化该过程:

  1. 基于该Bug,可以得到

    testby
    测试用例,我们可以使用rest api Wiql - Query By Wiql来实现相同的目的。 enter image description here

  2. 根据测试用例id,我们可以搜索测试点,如果其属性具有相同的测试用例id,则获取测试点id。

  3. 有了测试点id,使用rest api Points - Update重置为活动状态。

powershell 脚本示例:

# Define your parameters
$organization = "orgname"
$project = "projectname"
$bugId = "7742"
$personalAccessToken = "PAT"
$planId = "7570"
$suiteId = "7571"

# Define the WIQL query
$query = @"
{
    "query": "SELECT [System.Id], [System.Title], [System.WorkItemType] FROM WorkItemLinks WHERE ([Source].[System.Id] = $bugId) AND ([System.Links.LinkType] = 'Tested By')"
}
"@

# Define the REST API URL
$url = "https://dev.azure.com/$organization/$project/_apis/wit/wiql?api-version=7.1"

# Convert the personal access token to a Base64 string
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))


# Send the REST API request and get the response
$response = Invoke-RestMethod -Uri $url -Method Post -Body $query -Headers @{Authorization="Basic $base64AuthInfo"} -ContentType "application/json"

# Filter the workItemRelations array and output the URL of the target work item where rel is "Microsoft.VSTS.Common.TestedBy-Forward"
$testcaseid = $response.workItemRelations | Where-Object { $_.rel -eq "Microsoft.VSTS.Common.TestedBy-Forward" } | ForEach-Object { $_.target.id }
$testcaseurl = $response.workItemRelations | Where-Object { $_.rel -eq "Microsoft.VSTS.Common.TestedBy-Forward" } | ForEach-Object { $_.target.url }

# Output the URL
echo "test case id is:" $testcaseid               # the test case id
echo "test case url is:" $testcaseurl              # the test case url 


# Define the REST API URL
$url = "https://dev.azure.com/$organization/$project/_apis/testplan/Plans/$planId/Suites/$suiteId/TestPoint?api-version=7.1-preview.2"


# Send the REST API request and get the response
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{Authorization="Basic $base64AuthInfo"} -ContentType "application/json"

#$response.value.testCaseReference.id

$testpoint= $response.value | Where-Object { $_.testCaseReference.id -eq $testcaseid }

$testpointid = $testpoint.id

echo "test point id is:" $testpointid    # get the test point id

# Define the REST API URL
$url = "https://dev.azure.com/$organization/$project/_apis/test/Plans/$planId/suites/$suiteId/points/$testpointid" + "?api-version=7.1-preview.2"
     
# Define the request body
$body = @"
{
  "resetToActive": "true"
}
"@


# Send the REST API request and get the response
$response = Invoke-RestMethod -Uri $url -Method Patch -Body $body -Headers @{Authorization="Basic $base64AuthInfo"} -ContentType "application/json"

# Output the response
$response

输出:

enter image description here

enter image description here

我完全理解您的担忧,如果您希望在解决链接的错误时自动将测试点的状态从

Error
重置为
Active
,建议在社区链接此处提出功能请求,谢谢。

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