2017-05-22 66 views
0

我正在嘗試使用Team Foundation Server電源工具(tfpt)以編程方式創建工作項。我需要以這種方式創建很多測試用例。不幸的是,這些電動工具很大程度上沒有記錄,但我已將其追溯到最後剩下的一小部分。我需要能夠與測試案例一起創建測試步驟。這是通過一個名爲Steps=如何爲TFS/VSTS工作項查詢格式化HTML字段

外業完成:/fields: "Title=My Title;Steps="

現在只要我能在野外探險挖,下面的步驟文本必須是「HTML格式」但我不知道是什麼微軟對HTML的定義是什麼,標籤應該是什麼才能正確提供數據。

任何幫助非常感謝

+0

看來你不能用tfpt工具來做。 –

回答

1

它一般HTML格式化的值,例如<div></div>, <B></B>.細節值將被編碼。你可以通過online tool獲得編碼值。

在另一方面,有更多的信息表明測試步驟的動作,例如:<step id=」4」 type=」ActionStep」> <parameterizedString isformatted="true"></ parameterizedString></step>.

一個簡單的步進值:

<steps id=\"0\" last=\"4\"><step id=\"2\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;st&lt;B&gt;ep&lt;/B&gt;1&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step><step id=\"3\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;st&lt;I&gt;ep&lt;/I&gt;2&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step><step id=\"4\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;s&lt;U&gt;te&lt;/U&gt;p3&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step></steps> 

enter image description here

我建議你可以創建測試通過使用TFS/VSTS API(客戶端SDK或Rest API)案例

C#代碼:

NetworkCredential cred = new NetworkCredential("XXX", "XXX"); 
    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("[collection url]"), cred); 
      tpc.EnsureAuthenticated(); 

      var workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore)); 
      Project teamproject = workItemStore.Projects["ScrumStarain"]; 
      WorkItemType testCaseType = teamproject.WorkItemTypes["Test Case"]; 

      WorkItem testCase = new WorkItem(testCaseType) 
      { 
       Title="TestCaseApi2" 
      }; 
      testCase.Fields["Microsoft.VSTS.TCM.Steps"].Value = "[previous sample value]"; 
      testCase.Save(); 

另外,還可以通過使用此代碼得到測試用例步進值:

var wit = workItemStore.GetWorkItem(408); 
object stepValue = wit.Fields["Microsoft.VSTS.TCM.Steps"].Value; 

REST API:Create a work item

體樣本:

[ 
    { 
    "op": "add", 
    "path": "/fields/System.Title", 
    "value": "newTestcase" 
    }, 
    { 
    "op": "add", 
    "path": "/fields/Microsoft.VSTS.TCM.Steps", 
    "value": "<steps id=\"0\" last=\"4\"><step id=\"2\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;st&lt;B&gt;ep&lt;/B&gt;1&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step><step id=\"3\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;st&lt;I&gt;ep&lt;/I&gt;2&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step><step id=\"4\" type=\"ActionStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;s&lt;U&gt;te&lt;/U&gt;p3&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description /></step></steps>" 
    } 
] 
+0

你是一個GODSEND。如果有什麼我可以做的,以報答你,請讓我知道! – Shibumi