0

I'm going over all test cases under a specific test plan, and for each test case I want to print the parameter name and values.

foreach(var param in test.TestParameter)
{

}

The problem is that item.Value is null. item.Name returns the parameter name. Does anyone knows how to get the values of a parameter?

Thanks.

user963491
  • 151
  • 1
  • 8
  • Not really sure what your asking here. But why not just do: item.Name.tostring() inside your loop? Or if null is a concern, check if not null first. – Botonomous Jul 13 '12 at 21:27
  • I want the name of the parameter and its values. The problem is that the value is null. – user963491 Jul 15 '12 at 06:27
  • If the value is null, then nothing is there. So in your loop. Just output the parameters that ARE NOT NULL. Check with an IF statement. – Botonomous Jul 16 '12 at 16:16

3 Answers3

2

Test parameter values are stored in TestCase objects TestSuiteEntry attribute. You can call it by TestSuiteEntry.TestCase.DefaultTable.Rows[0].ItemArray

cerezza
  • 251
  • 3
  • 14
2

with this code you can get all parameter for a test case as a DataRow[]

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URL"));
ITestManagementTeamProject project = tfs.GetService<ITestManagementService>().GetTeamProject("ProjectName");
var testCase = project.TestCases.Find(1234);
var testData = testCase.Data.Tables[0];
this._dataSource = testData.Select();

If you want to get the parameters with attributes, you can see my repository on GitHub Click here!

Daniel
  • 9,491
  • 12
  • 50
  • 66
Majdi Barrat
  • 141
  • 7
0

Since I banged my head against the wall to figure this out in powershell I thought I'd share it with everyone:

$ProjectName = "foo"
$TfsServerUrl = "http://tfsserverurl:8080/tfs/bar"
$testPlanName = "testplanname"

#===================================================
#     Settings
#===================================================

Write-Host "Input parameters: "
$ParamObject = @{
 'ProjectName' = $ProjectName;
 'TfsServerUrl' = $TfsServerUrl;
 'testPlanName' = $testPlanName;
}
$ParamObject | Format-Table

#===================================================
#    Main Script Body
#===================================================

  #load assemblies
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.TestManagement.Common")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.TestManagement.Client")
    #get TFS structure, project
 $tfs = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection([Microsoft.TeamFoundation.Client.TfsTeamProjectCollection]::GetFullyQualifiedUriForName($tfsServerUrl));
 $tms = $tfs.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService]);
 $project = [Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject]$tms.GetTeamProject($ProjectName);
 #powershell bug workaround, $project.TestPlans property is not available
 $testPlansProperty = [Microsoft.TeamFoundation.TestManagement.Client.ITestManagementTeamProject].GetProperty("TestPlans").GetGetMethod();
 $testPlans = $testPlansProperty.Invoke($project, "instance,public", $null, $null, $null);
#   List all Test Plans
 foreach($p in $testPlans.Query("Select * From TestPlan"))
 {
  "Plan - {0} : {1}" -f $p.Id, $p.Name
 }
 $currentPlan = $testPlans.Query("Select * From TestPlan Where planName = '{0}'" -f $testPlanName)
 $plan = $currentPlan | where {$_.Name -eq $testPlanName}

 $testCases = $plan.RootSuite.AllTestCases


 foreach($testCase in $testCases)
 {
  write-host ""
  write-host "-----------"
  write-host "START - Test Case"  $testCase.Id
   write-host "Parameters:"

$testCase.TestSuiteEntry.TestCase.DefaultTable  
  write-host "-----------"
}
brakertech
  • 1,467
  • 1
  • 13
  • 20