-1

I am trying to create a work item of type test case in TFS using c# in visual studio. I am able to set the values of all fields except the field "steps". How to set the step field's value?

I tried workitem.Fields["steps"].value = "value" but is not working.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114

2 Answers2

0

That`s not working because you have to use reference to TestManagement Client. Then get your test case and add new steps like this:

TfsTeamProjectCollection tfs;

tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(uri)); 
tfs.Authenticate();

ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testProject = service.GetTeamProject(project);    

ITestCase testCase = TestProject.TestCases.Find(1);
ITestStep newStep = testCase.CreateTestStep();
newStep.Title = "New Step Title";
newStep.ExpectedResult = "New Step Expected Result";
testCase.Actions.Add(newStep);

Look these links:

  1. Programmatically Create Test Case Steps
  2. TFS API Part 51 – Adding Test Step & Shared Step
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
0

Please notice the Steps field is html type. You could try to use REST API to set steps' value. An example is as below:

POST https://xxxx.visualstudio.com/{teamproject}/_apis/wit/workitems/$Test%20Case?api-version=4.1

Content-Type: application/json-patch+json

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample testcase"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.Steps",
    "from": null,
    "value": "<steps id=\"0\" last=\"3\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;step1&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;&amp;nbsp;0&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><description/></step><step id=\"3\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">&lt;DIV&gt;&lt;P&gt;step2&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</parameterizedString><parameterizedString isformatted=\"true\">&lt;P&gt;&amp;nbsp;pass&lt;/P&gt;</parameterizedString><description/></step></steps>"
  }
]
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39