How to update the test results in VSTS/Microsoft Test Manager using APIs. How to update the test results in VSTS/Microsoft Test Manager using Selenium/Java.
Procedure to update the test results through APIs:
First get the testPoints of the test case using following API: For this you need plan id, suite id, and test case id. Open the suite in web view, in URL you can find plan id and suite id, test case id is id of the test case.
GET https://{instance}/DefaultCollection/{project}/_apis/test/plans/{plan}/suites/{suite}/points?api-version={version}&testCaseId={string}
Send the request and note the the testPoints (in response).
For details refer: https://learn.microsoft.com/en-us/vsts/integrate/previous-apis/test/points?view=vsts#get-a-test-point
POST https://{instance}/DefaultCollection/{project}/_apis/test/runs?api-version={version}
Sample body
{
"name": "Sprint 10 Test Run",
"plan": {
"id": 1234
},
"pointIds": [
10
]
}
Send the request and note the run id (response).
For details refer: https://learn.microsoft.com/en-us/vsts/integrate/previous-apis/test/runs?view=vsts#create-new-test-run
POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results?api-version={version}
Sample body
[
{
"state": "Completed",
"testPoint": {
"id": 10
},
"outcome": "Passed",
"testCase": {
"id": 4567
}
}
]
Send the request and note result id (from response).
For details refer: https://learn.microsoft.com/en-us/vsts/integrate/previous-apis/test/results?view=vsts#add-test-results-to-a-test-run
PATCH
https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}?api-version={version}
Sample body
[
{
"id": 100000,
"state": "Completed"
}
]
For details refer: https://learn.microsoft.com/en-us/vsts/integrate/previous-apis/test/runs?view=vsts#update-test-run
Now check VSTS/Test Manager for result updates. Additionally you can update the results for specific configuration also, just add configuration also in the body of add test results. For configuration details refer: https://learn.microsoft.com/en-us/vsts/integrate/previous-apis/test/configurations?view=vsts#get-a-list-of-test-configurations
Now to update the results using Java, use RestAssured to send get, post, patch request and retrieve the specific data from the response. For rest-assured details refer: https://github.com/rest-assured/rest-assured/wiki/Usage
For sending post and patch request you may want to create json objects/bodies, for that use minidev json libraries. How to create json object/array: How to create JSON Object using String?