[英]Powershell - script to migrate test cases from TFS to Azure DevOps
[英]how to clone parameters in from tfs test cases to vsts using powershell
嗨,我有一個powerShell腳本,它將腳本從TFS2012到VSTS克隆帶有參數的測試用例,但是我無法獲取要克隆的參數值。
第一部分僅確定兩個項目的位置
$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();
}
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.