I am trying to use the Team Foundation Server Power Tools (tfpt) to create workitems programmatically. I need to create many test cases this way. The power tools are largely undocumented unfortunately but I have traced it down to one last remaining bits. I need to be able to create test steps alongside the test case. This is done with a field called Steps=
For Example: /fields: "Title=My Title;Steps="
Now digging as far as I could in the field explorer, the text that follows steps has to be "HTML formatted" But I have no idea what Microsoft's definition of HTML is and what the tags should be in order to properly serve the data.
Any help is much appreciated
It is general HTML formatted value, for example <div></div>, <B></B>.
The detail value will be encoded. You can get encoded value via online tool.
On the other hand, there is additional information indicate test step actions, for example: <step id=”4” type=”ActionStep”> <parameterizedString isformatted="true"></ parameterizedString></step>.
A simple step value:
<steps id=\"0\" last=\"4\"><step id=\"2\" type=\"ActionStep\"><parameterizedString isformatted=\"true\"><DIV><DIV><P>st<B>ep</B>1&nbsp;</P></DIV></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step><step id=\"3\" type=\"ActionStep\"><parameterizedString isformatted=\"true\"><DIV><DIV><P>st<I>ep</I>2&nbsp;</P></DIV></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step><step id=\"4\" type=\"ActionStep\"><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;s<U>te</U>p3</P></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step></steps>
I recommend that you can create test case by using TFS/VSTS API (Client SDK or Rest API)
C# code:
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();
Also, you can get a test case step value by using this code:
var wit = workItemStore.GetWorkItem(408);
object stepValue = wit.Fields["Microsoft.VSTS.TCM.Steps"].Value;
Rest API: Create a work item
Body sample:
[
{
"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\"><DIV><DIV><P>st<B>ep</B>1&nbsp;</P></DIV></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step><step id=\"3\" type=\"ActionStep\"><parameterizedString isformatted=\"true\"><DIV><DIV><P>st<I>ep</I>2&nbsp;</P></DIV></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step><step id=\"4\" type=\"ActionStep\"><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;s<U>te</U>p3</P></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;</P></DIV></parameterizedString><description /></step></steps>"
}
]