空手道:多部分文件:读取有效但传递值内容失败

Karate: Multipart file : read works but passing content in value fails

我有一个包含多部分请求的端点,该请求将两个文件作为请求参数的一部分。 我尝试使用以下代码片段进行读取并且它有效,但我的用例是从文件中获取内容并将其传递给 value 参数。 我可以将内容作为文件传递吗?

如果我尝试从目录中读取文件,工作代码是

工作特征::

Scenario:
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { read: './oldfile.json', filename: 'oldfile.json'}
And multipart file newfile = { read: './newfile.json', filename: newfile.json'}
When method post
Then status 200

功能无效::

Scenario:
Given url "http://download-oldfile/oldfile"
When method get
* def oldfile = response
Given url "http://download-newfile/newfile"
When method get
* def newfile = response
* configure headers = {'Content-Type' : 'multipart/form-data', 'Authorization': 'Bearer sgahshshshs'}
Given url "http://filecompare.com/compare"
And multipart file oldfile = { value: '#(oldfile)', filename: 'oldfile.json'}
And multipart file newfile = { value: '#(newfile)', filename: newfile.json'}
When method post
Then status 200

内容打印正确但apireturns使用值

时出错

如果我遗漏了 运行 多部分文件中值关键字的一部分,请告诉我。 谢谢

除了尝试将值转换为字符串之外,想不出别的办法:

* string oldfile = response

如果仍然卡住,请按照以下流程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

有同样的问题,通过定义一个包含 JSON 对象的变量并使用 set 来操作它的值,无需保存到文件即可解决。

在你的情况下,这看起来像:

* def temp = {value: '', filename: 'oldfile.json'}
* set temp.value = oldFile
#[...]
And multipart file oldFile = temp