3

Image of Test Case I have created a custom work item in which i have successfully managed to call api to create work item but i have no idea how to create test steps for that work item.

 let body = [
      {
        "op": "add",
        "path": "/fields/System.Title",
        "from": null,
        "value": "Sample1"
      },
      {
        "op": "add",
        "path": "/fields/Microsoft.VSTS.TCM.Steps",
        "value":"<Steps id=\"0\">     <step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step>     <step id=\"3\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 2</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 2</parameterizedString><description/></step></Steps>"
      },
    ]
    fetch(`https://dev.azure.com/${organizationName}/${projectId}/_apis/wit/workitems/$CUSTOM TASK 1?api-version=7.1-preview.3`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json-patch+json',
        'Authorization': 'Basic ' + btoa("" + ":" + token)
      },
      body: JSON.stringify(body)
    })

i have tried the above code but it just creates a work item but the test steps are not visible in the work item This is what i get in response:

fields:
Microsoft.VSTS.TCM.Steps: "<steps id=\"0\">     <step id=\"1\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step>     <step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 2</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 2</parameterizedString><description/></step></steps>"
System.AreaPath: "Azure devops test  demo"
System.ChangedBy: {displayName: 'sid vaidya', url: 'https://spsprodsin2.vssps.visualstudio.com/A120553…s/Identities/7131ed99-7bde-6f31-8161-653548dbc4fe', _links: {…}, id: '7131ed99-7bde-6f31-8161-653548dbc4fe', uniqueName: 'sidvaidya34@gmail.com', …}
System.ChangedDate: "2022-03-09T05:07:10.04Z"
System.CommentCount: 0
System.CreatedBy: {displayName: 'sid vaidya', url: 'https://spsprodsin2.vssps.visualstudio.com/A120553…s/Identities/7131ed99-7bde-6f31-8161-653548dbc4fe', _links: {…}, id: '7131ed99-7bde-6f31-8161-653548dbc4fe', uniqueName: 'sidvaidya34@gmail.com', …}
System.CreatedDate: "2022-03-09T05:07:10.04Z"
System.IterationPath: "Azure devops test  demo"
System.Reason: "Moved to state To do"
System.State: "To do"
System.TeamProject: "Azure devops test  demo"
System.Title: "Steps"
System.WorkItemType: "Custom Task 1"
KR Akhil
  • 877
  • 3
  • 15
  • 32
Sid Vaidya
  • 33
  • 4

2 Answers2

1

Your XML is slightly off, that's what's causing the issue. There are two small issues I saw that when corrected, allow the steps to properly be interpreted by the work item:

  1. <Steps /> should be LOWERCASE <steps />
  2. Your step Ids start at 2 instead of 1

Try this XML:

<steps id=\"0\"> <step id=\"1\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step> <step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 2</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 2</parameterizedString><description/></step></steps>

Max Morrow
  • 1,206
  • 4
  • 13
1

It is caused by the "Microsoft.VSTS.TCM.Steps" field in your custom work item. Based on the screenshot you provided, it is a text(mulit-line) type field.

The text(mulit-line) field cannot resolve your XML. You may try with HTML if you need the similar content:

<table><tr><th>Steps</th><th>Action</th><th>Expected Results</th></tr><tr><td>1</td><td>Input step 1</td><td>Expectation step 1</td></tr></table>