[英]how to clone parameters in from tfs test cases to vsts using powershell
Hi I have a powerShell script which will clone a test case with parameters from TFS2012 to VSTS, but I can't get the parameter values to clone. 嗨,我有一个powerShell脚本,它将脚本从TFS2012到VSTS克隆带有参数的测试用例,但是我无法获取要克隆的参数值。
This first section just identifies the location of the two projects 第一部分仅确定两个项目的位置
$VerbosePreference = "Continue"
$tfsSource="http://server:8080/tfs/DefaultCollection/";
$tpSource="My Project in TFS";
$tfsDest="https://server.visualstudio.com:443";
$tpDest="My Project in VSTS";
[Reflection.Assembly]::LoadWithPartialName(‘Microsoft.TeamFoundation.Client’)
[Reflection.Assembly]::LoadWithPartialName (‘Microsoft.TeamFoundation.TestManagement.Client’)
[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\Newtonsoft.Json.dll")
$sourceTpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsSource)
$sourceTcm = $sourceTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$sourceProject = $sourceTcm.GetTeamProject($tpSource);
#$sourceTestCases = $sourceProject.TestCases.Query(“SELECT * FROM WorkItem”);
$sourceTestCases = $sourceProject.TestCases.Query(“SELECT * FROM WorkItem where State = 'Ready' AND Title contains 'Parameter Test'");
$destTpc= [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsDest)
$destTcm = $destTpc.GetService([Microsoft.TeamFoundation.TestManagement.Client.ITestManagementService])
$destProject = $destTcm.GetTeamProject($tpDest);
#The next steps will copy the test case steps from old project to the new project
foreach ($tc in $sourceTestCases)
{
Write-Verbose ("Copying Test Case {0} - {1}" -f $tc.Id, $tc.Title)
$destTestCase= $destProject.TestCases.Create();
$destTestCase.Title = $tc.Title;
$destTestCase.Priority = $tc.Priority;
foreach ($step in $tc.Actions)
{
$destStep= $destTestCase.CreateTestStep();
$destStep.Title= $step.Title
$destStep.TestStepType= $step.TestStepType
$destStep.Description= $step.Description
$destStep.ExpectedResult= $step.ExpectedResult;
$destTestCase.Actions.Add($destStep);
}
#The next steps bring in the parameters. This is where the problem is.
foreach ($pv in $tc."Parameters")
{
$destpv= $destTestCase.CreateParameterValue();
$destpv."Parameter value"= $pv."Parameter value";
$destTestCase.Actions.Add($destpv);
}
$destTestCase.Save();
}
There isn't Parameters property in ITestCase ($tc), using this code instead to copy parameters' data: ITestCase($ tc)中没有Parameters属性,而是使用以下代码复制参数的数据:
#......
#The next steps bring in the parameters. This is where the problem is.
# foreach ($pv in $tc."Parameters")
#{
# $destpv= $destTestCase.CreateParameterValue();
# $destpv."Parameter value"= $pv."Parameter value";
# $destTestCase.Actions.Add($destpv);
#}
$ts = $tc.Data.Tables;
for($tri=0;$tri -lt $ts[0].Rows.Count;$tri++)
{
$newRow=$destTestCase.Data.Tables[0].NewRow()
foreach($tc in $ts[0].Columns)
{
$newRow[$tc.ColumnName]=$ts[0].Rows[$tri][$tc]
}
$destTestCase.Data.Tables[0].Rows.Add($newRow)
}
$destTestCase.Save();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.