You can actually get the test id - its what is printed out as a result of tcm.exe run /create command
in powershell it would be something like this:
$testRunSubmitResult = .$tcmPath run /create ......
$testID = $testRunSubmitResult -match "[0-9]{1,1000}"
(i excluded the error handling logic which needs to be present in order to verify that the run was submitted)
after that you can do the following thing - you can export the test run with the used id, and if the test didnt finish yet, you will get and error.
do
{
Start-Sleep -s 60
$testResults = .$tcmPath run /export /id:$testID /resultsfile:$args /collection ....
if(Test-Path $args[0])
{
break
}
if($testResults.GetType() -eq @("1").GetType())
{
if($testResults[1].Contains("Completed export"))
{
break
}
}
if ($testResults.Contains("Completed export"))
{
break
}
}
while ($True)
This is not perfect as it might fail in test runs with big attachments (such as ones produced by the Video data collector) but it might be a solution for some of you
Or alternatively from powerscript you can just use the TFS API like this:
Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.TeamFoundation.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"Microsoft.TeamFoundation.TestManagement.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
$tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection("http://tfs:8080/tfs/Collection")
$tfs.EnsureAuthenticated()
$testManagementService = $tfs.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$testManagementTeamProject = $testManagementService.GetTeamProject('Project');
do
{
Start-Sleep -s 60
$testRun = $testManagementTeamProject.TestRuns.Find($testId);
if($testRun.State -eq 'Completed')
{
break
}
if($testRun.State -eq 'NeedsInvestigation')
{
break
}
if($testRun.State -eq 'Aborted')
{
break
}
}