mercredi 9 janvier 2019

How to add test steps in a test case work item using Rest API - TFS2018 / Python

I am using Microsoft's TFS 2018 and I have started writing some Selenium test cases using Python 3.7 in Visual Studio 2018.

I have managed to use the REST API of TFS to return my TFS projects and create new test cases.

What I couldn't find is how to use this API to pass a list with all the test steps of this test case. I am not sure how and if you can add them in the body of the request as a string or array.

At the moment I am trying to make this work on Postman first and then I am going to try in python as well.

This is the request:

curl -X POST \
  'https://TFSLINK:443/DefaultCollection/TFS/_apis/wit/workitems/$Test%20Case?api-version=4.1' \
  -H 'Authorization: Basic MYKEY' \
  -H 'Content-Type: application/json-patch+json' \
  -H 'cache-control: no-cache' \
  -d '[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample task 2"
  }
]'

Is there a way to achieve adding steps ? The API didn't mention anything about this.

In the response I get after creating a test case I get a section called 'fields' which should have included the steps but I can't see them in my response.

{
    "id": 731,
    "rev": 1,
    "fields": {
        "System.AreaPath": "TFS",
        "System.TeamProject": "TFS",
        "System.IterationPath": "TFS",
        "System.WorkItemType": "Test Case",
        "System.State": "Design",
        "System.Reason": "New",
        "System.AssignedTo": "Marialena <TFS\\marialena>",
        "System.CreatedDate": "2019-01-09T08:00:50.51Z",
        "System.CreatedBy": "Marialena <TFS\\marialena>",
        "System.ChangedDate": "2019-01-09T08:00:50.51Z",
        "System.ChangedBy": "Marialena <TFS\\marialena>",
        "System.Title": "Sample task 2",
        "Microsoft.VSTS.Common.StateChangeDate": "2019-01-09T08:00:50.51Z",
        "Microsoft.VSTS.Common.ActivatedDate": "2019-01-09T08:00:50.51Z",
        "Microsoft.VSTS.Common.ActivatedBy": "Marialena <TFS\\marialena>",
        "Microsoft.VSTS.Common.Priority": 2,
        "Microsoft.VSTS.TCM.AutomationStatus": "Not Automated"
    },
    "_links": {
        "self": {
            "href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
        },
        "workItemUpdates": {
            "href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/updates"
        },
        "workItemRevisions": {
            "href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/revisions"
        },
        "workItemHistory": {
            "href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/history"
        },
        "html": {
            "href": "https://TFSLINK/web/wi.aspx?pcguid=07b658c4-97e5-416f-b32d-3dd48d7f56cc&id=731"
        },
        "workItemType": {
            "href": "https://TFSLINK/DefaultCollection/18ca0a74-cf78-45bf-b163-d8dd4345b418/_apis/wit/workItemTypes/Test%20Case"
        },
        "fields": {
            "href": "https://TFSLINK/DefaultCollection/_apis/wit/fields"
        }
    },
    "url": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
}


And maybe this is a another topic but if the above is achievable, can you also pass the results after you run the test and update the test plan perhaps ? If this is unrelated please help me only with the test steps and ignore this question.

Many thanks.

Aucun commentaire:

Enregistrer un commentaire