2

我正在尝试为导入执行结果调用“POST /rest/raven/1.0/import/execution/cucumber/multipart” - REST

由于此端点允许您发送两个 JSON 文件,因此我编写了以下空手道测试

@UploadResultMultiPartURL 场景:将执行结果导出到 xray 测试计划给定路径 'import/execution/cucumber/multipart' 和 header Authorization = 'Bearer' + accessToken 和 multipart file info = { read('classpath:data/testplanwithkey.json') , filename: 'testplanwithkey.json', contentType: 'application/json' } and multipart file result = { read('classpath:JiraReports/cucumber.json'), filename: 'cucumber.json', contentType: 'application/json ' } 当方法发布并打印响应时

我怎么是空手道响应
15:50:50.334 [打印] {“错误”:“意外字段(结果)”}

我已附上我的空手道结果文件以供参考。请让我哪里出错了。

在此处输入图像描述

我也尝试了与rest api相同的方法,我将使用它上传结果,但不确定空手道哪里出了问题: ResponseBody responseBody = given() .multiPart("results", new File(CUCUMBER_RESULT_FILE)) .mul .multiPart("info", "info.json", jiraExecutionJson.getBytes()) .header("Authorization", "Bearer " + jiraTokenGenerator.getXrayToken()) .post(JIRA_IMPORT_EXECUTION_MULTIPART_URL) .getBody();

4

2 回答 2

1

问题似乎出在你的空手道规范中,你有一个名为“result”的多部分,它应该被命名为“results”。

And multipart file results = ....

仅供参考,您可以在此处看到实现类似请求的python 代码。

于 2022-01-03T17:40:12.210 回答
1

我终于设法通过使用 value: alternative to read 解决了这个问题,在极少数情况下,正在上传 JSON 或 XML 文件之类的文件并且您希望动态创建它。所以早些时候我试图阅读 json And multipart file info = { read('classpath:data/testplanwithkey.json'), filename: 'testplanwithkey.json' } 这对我有用

 And def value = read('classpath:data/testplanwithkey.json')
And multipart file info = { value: '#(value)', filename: 'testplanwithkey.json' }
于 2022-01-04T12:11:15.757 回答