我有一个端点,它有一个多部分请求,它接受两个文件作为请求参数的一部分。我使用read尝试了下面的代码片段,它起作用了,但我的用例是从文件中获取内容并将其传递给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当我使用value时,内容打印正确,但api返回错误
如果我在多部分文件中使用value关键字运行时遗漏了什么,请让我知道。谢谢
发布于 2020-08-26 10:31:28
除了尝试将值转换为字符串之外,我不能想到其他任何事情:
* string oldfile = response如果仍然卡住,请遵循以下过程:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
发布于 2021-08-19 08:39:39
也有同样的问题,通过定义一个保存JSON对象的变量并使用set操作它的值,解决了这个问题,而无需保存到文件中。
在您的示例中,这将如下所示:
* def temp = {value: '', filename: 'oldfile.json'}
* set temp.value = oldFile
#[...]
And multipart file oldFile = temphttps://stackoverflow.com/questions/63584649
复制相似问题