【发布时间】:2019-01-09 18:02:07
【问题描述】:
我正在使用 Microsoft 的 TFS 2018,并且我已经开始在 Visual Studio 2018 中使用 Python 3.7 编写一些 Selenium 测试用例。
我已经设法使用 TFS 的 REST API 返回我的 TFS 项目并创建新的测试用例。
我找不到的是如何使用此 API 传递包含此测试用例的所有测试步骤的列表。我不确定如何以及是否可以将它们作为字符串或数组添加到请求正文中。
目前我正在尝试先在 Postman 上进行这项工作,然后我也将在 python 中尝试。
这是请求:
curl -X POST \
'https://TFSLINK:443/DefaultCollection/TFS/_apis/wit/workitems/$Test%20Case?api-version=4.1' \
-H 'Authorization: Basic MYKEY' \
-H 'Content-Type: application/json-patch+json' \
-H 'cache-control: no-cache' \
-d '[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task 2"
}
]'
有没有办法实现添加步骤? API 没有提及此事。
在创建测试用例后得到的响应中,我得到一个名为“字段”的部分,其中应该包含这些步骤,但我在响应中看不到它们。
{
"id": 731,
"rev": 1,
"fields": {
"System.AreaPath": "TFS",
"System.TeamProject": "TFS",
"System.IterationPath": "TFS",
"System.WorkItemType": "Test Case",
"System.State": "Design",
"System.Reason": "New",
"System.AssignedTo": "Marialena <TFS\\marialena>",
"System.CreatedDate": "2019-01-09T08:00:50.51Z",
"System.CreatedBy": "Marialena <TFS\\marialena>",
"System.ChangedDate": "2019-01-09T08:00:50.51Z",
"System.ChangedBy": "Marialena <TFS\\marialena>",
"System.Title": "Sample task 2",
"Microsoft.VSTS.Common.StateChangeDate": "2019-01-09T08:00:50.51Z",
"Microsoft.VSTS.Common.ActivatedDate": "2019-01-09T08:00:50.51Z",
"Microsoft.VSTS.Common.ActivatedBy": "Marialena <TFS\\marialena>",
"Microsoft.VSTS.Common.Priority": 2,
"Microsoft.VSTS.TCM.AutomationStatus": "Not Automated"
},
"_links": {
"self": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
},
"workItemUpdates": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/updates"
},
"workItemRevisions": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/revisions"
},
"workItemHistory": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/history"
},
"html": {
"href": "https://TFSLINK/web/wi.aspx?pcguid=07b658c4-97e5-416f-b32d-3dd48d7f56cc&id=731"
},
"workItemType": {
"href": "https://TFSLINK/DefaultCollection/18ca0a74-cf78-45bf-b163-d8dd4345b418/_apis/wit/workItemTypes/Test%20Case"
},
"fields": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/fields"
}
},
"url": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
}
我已尝试创建此 PATCH 请求以更新步骤,但没有成功
curl -X PATCH \
'https://TFSLINK:443/DefaultCollection/TFS/_apis/wit/workItems/730?api-version=4.1' \
-H 'Authorization: Basic MYKEY' \
-H 'Content-Type: application/json-patch+json'
-d '[
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.Steps",
"from": null,
"value": "Test"
},
{
"op": "add",
"path": "/fields/Steps",
"from": null,
"value": "Test"
}
]'
也许这是另一个话题,但如果上述是可以实现的,你是否也可以在运行测试并更新测试计划后通过结果?如果这无关,请仅帮助我完成测试步骤并忽略此问题。
非常感谢。
【问题讨论】:
标签: api testing tfs request postman