You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Azure DevOps API获取所有测试用例步骤数据?

Retrieving Test Case Steps via Azure DevOps API

Absolutely! You can definitely fetch all test case steps using the Azure DevOps REST API. Let me break down the process clearly, with actionable examples:

1. Choose the Right API Endpoint

Test cases are treated as work items in Azure DevOps, so you have two main options:

  • Single test case: Use the Test Cases - Get Test Case endpoint to pull details for one specific test case.
  • Multiple test cases: Use the Work Items - List endpoint (or query via WIQL) to retrieve steps for a batch of test cases.

2. Example: Fetch a Single Test Case's Steps

Send a GET request to this endpoint (replace placeholders with your org/project/test case ID):

GET https://dev.azure.com/{organization}/{project}/_apis/test/testcases/{testCaseId}?api-version=7.1-preview.3

In the JSON response, look for the Microsoft.VSTS.TCM.Steps field under workItem.fields. This field stores all test steps as an XML string. Here's a snippet of what that might look like:

"fields": {
  "Microsoft.VSTS.TCM.Steps": "<steps><step id=\"1\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Action: Navigate to login page</parameterizedString><parameterizedString isformatted=\"true\">Expected: Login form is displayed</parameterizedString></step><step id=\"2\" type=\"ValidateStep\">...</step></steps>"
}

3. Example: Fetch Steps for Multiple Test Cases

To get steps for multiple test cases at once, use the Work Items List endpoint with a comma-separated list of IDs and specify the Microsoft.VSTS.TCM.Steps field:

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids=123,456,789&fields=Microsoft.VSTS.TCM.Steps&api-version=7.1-preview.3

If you need to filter test cases by criteria like area path or iteration, use the Queries - Query By Wiql endpoint to run a WIQL query (e.g., SELECT [System.Id], [Microsoft.VSTS.TCM.Steps] FROM WorkItems WHERE [System.WorkItemType] = 'Test Case'), then fetch the work items from the query results.

4. Key Tips

  • Permissions: Ensure you have Read access to the test cases in your project—without this, the API will return a 403 error.
  • Parsing XML: Since steps are stored as XML, you’ll need to parse this string in your code (using an XML parser library) to extract individual step actions and expected results.
  • API Versions: Stick to the latest stable preview version (check Azure DevOps documentation for updates) to avoid hitting deprecated endpoints.

内容的提问来源于stack exchange,提问作者Andrey Kudin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 21:37:39