I have a requirement to run automated API test (associated to a test case) in Azure Devops.
I can run it manually by selecting - build and release.
Since I'm running the testcases from Azure Devops yaml pipeline on a Linux agent, I cannot use VSTEST@2 task to input - TestPlan , TestSuite id's.
The only option I found is to run via, APIs - and call the API via - bash task.
Here is the script
param (
[string]$token="",
[string]$collection="",
[string]$projectName ="",
[int] $planIdStatic = ,
[int] $suiteIdStatic = ,
[int] $testcaseID =
)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $token)))
$response = Invoke-RestMethod "https://dev.azure.com/$collection/$projectName/_apis/test/plans?api-version=5.0" -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
foreach( $val in $response.value)
{
#PLAN ID
Write-Host $val.id
# $planId = [convert]::ToInt32($val.id)
[int] $planId = $planIdStatic
$suites = "https://dev.azure.com/$collection/$projectName/_apis/test/plans/$planId/suites?api-version=5.0"
$listofSuites = Invoke-RestMethod $suites -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
#define Suite ID
[int] $suiteId = $suiteIdStatic
$suitename = "https://dev.azure.com/$collection/$projectName/_apis/test/plans/$planId/suites/$suiteId/points?api-version=5.0"
$listofSuites = Invoke-RestMethod $suitename -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
#Define TestCaseID
[int] $tcID = $testcaseID
$tc = "https://dev.azure.com/$collection/$projectName/_apis/test/plans/$planId/suites/$suiteId/points?testCaseId=$tcID&api-version=5.0"
$testcaseapi = Invoke-RestMethod $tc -Method 'GET' -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
#Define PointID
[int] $pointID = $testcaseapi.value[0].id
$runName = "Test RUN Setup"
#PayLoad
$payload = @"
{
"name":"$runName",
"plan":{
"id":"$planId"
},
"pointIds":[
"$pointID"
]
}
"@;
#Initiate the RUN
$tcRun = "https://dev.azure.com/$collection/$projectName/_apis/test/runs?api-version=5.0"
$testRun = Invoke-RestMethod $tcRun -Method 'POST' -ContentType "application/json" -Body $payload -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)}
Write-Host "Test Run Status is ...."
}
From the blog - https://ghoshasish99.medium.com/integrate-your-test-automation-framework-with-azure-test-plan-a3230ab0f1da
Unfortunately it creates the test run - but it wont run any testcase it just shows as in-progress forever, and that's all - (Note - Test Plan is associated with Build and Release)
I suspect the script needs payload- body with build and release pipeline & release stage (Assume my release has DEV - QA and PROD) stages.