[英]How to add Test Case into TFS via REST
I'm implementing lib to export/synchronize test cases into TFS automaticaly during test run. 我正在实现lib以在测试运行期间自动将测试用例导出/同步到TFS中。 One of my requirements is that I need to use NodeJS for that, so I decided to use TFS REST API.
我的要求之一是为此需要使用NodeJS,因此我决定使用TFS REST API。 In my code I'm using "azure-devops-node-api " lib, I can connect and get different elements, no luck with adding test cases.
在我的代码中,我使用的是“ azure-devops-node-api”库,我可以连接并获取不同的元素,添加测试用例也很幸运。
I've found on the web that TestCase is kind of WorkItem and as WI should be added. 我在网上发现TestCase是一种WorkItem,应该添加WI。 Unfortunately I didn't find a way to add one with azure-devops-node-api.
不幸的是,我没有找到使用azure-devops-node-api添加一个的方法。
I tried also to send manually constructed json, unfortunatelly no luck with finding proper url to sent as I'm allways getting : 我也尝试发送手动构造的json,不幸的是,由于我一直都在获取要发送的适当的URL,因此运气不佳:
Error: {"statusCode":404,"body":"Page not found."
My example request: 我的示例请求:
request.post({
url: 'https://<url>/tfs/<default collection maybe?>/<project>/_apis/wit/workItems/test%20case',
headers: {
'Content-Type': 'application/json',
'Authorization':'Basic ' + this.encodePat('<my auth token>')
},
rejectUnauthorized: false,//add when working with https sites
requestCert: false,//add when working with https sites
agent: false,//add when working with https sites
json: rq
},function (response, err, body){
if (err) throw new Error(JSON.stringify(err));
console.log('Body:',JSON.parse(body));
console.log('Response:',response)
});
Does anyone know what wrom I'm doing or if azure-devops-node-api is able to add WorkItems ? 有谁知道我在做什么,或者azure-devops-node-api是否可以添加WorkItems?
If you want to add a test case only just as a work item you have to use the template from this link Work Items - Create . 如果您只想添加测试用例作为工作项,则必须使用此链接“ 工作项-创建”中的模板。
POST https://dev.azure.com/ {organization}/{project}/_apis/wit/workitems/${type}?api-version=5.0
POST https://dev.azure.com/ {organization} / {project} / _ apis / wit / workitems / $ {type}?api-version = 5.0
You have to add to url "?api-version=X.0". 您必须添加到网址“?api-version = X.0”。 The example:
这个例子:
https://<server name and port>/tfs/<collection name should be>/<project>/_apis/wit/workItems/$test%20case?api-version=3.0
Also you have to encode your pat by this template: 另外,您还必须通过以下模板对拍子进行编码:
'Authorization':'Basic ' + this.encodePat(':<my auth token>')
Here you can find an example for a build task with node.js: https://github.com/ashamrai/AzureDevOpsExtensions/blob/master/CustomBuildTask/NewWICustomTask/index.ts 在这里,您可以找到一个使用node.js的构建任务的示例: https : //github.com/ashamrai/AzureDevOpsExtensions/blob/master/CustomBuildTask/NewWICustomTask/index.ts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.