Ashish Bajpai
Ashish Bajpai

Reputation: 179

MTM : Is there a way to find test run completion status using command line utility tcm.exe

I use MTM (Microsoft test manager) for running my automated test cases.

I schedule test runs using tcm /create command (trigerred from a powershell script) and once the test run is completed I need to copy the trx (result) file on my local machine. So I want to wait till the test run is completed in some sort of polling mechanism.

Hence, I need a command to fetch the current test run status using test runid. Is there a way to get MTM test run status in this way?

Upvotes: 3

Views: 3133

Answers (2)

Stas Sh
Stas Sh

Reputation: 676

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
    }
}

Upvotes: 3

chaliasos
chaliasos

Reputation: 9783

I don't think this is possible. The available switches for run option are:

  • delete
  • abort
  • export
  • list
  • create
  • publish

The only data you can take about runs using /list is

  • Id
  • Title
  • Owner
  • Date Completed

you can see this by running:

tcm run /list /planid:<plainId> /collection:<CollectionUrl> /teamproject:<TeamProject>

Moreover, you don't have the runId yet so even if there was an option to get the completion status, in your case that would not be easy.

So, I think you should start looking for another solution. Perhaps the TFS Api is what you need. Check these links:

  1. Automation test run creation using tfs api
  2. TFS 2010 API - Get Results of a Test Run

Upvotes: 4

Related Questions