【发布时间】:2022-02-16 13:10:25
【问题描述】:
我正在尝试将 api 测试之一迁移到空手道框架。但是我无法编写空手道文档中定义的正确步骤。也许我遗漏了一些基本语法..但是任何人都知道我们如何在空手道功能中编写以下步骤
requestPostDoc.header("x-api-key","FG6dcYHN9N7PYKfWCUlGo5QGTwZhv2Re1MrDSOTV");//New chnages
requestPostDoc.contentType("multipart/form-data").multiPart("part2-file",file).formParam("part1-json",objDocumentWrite.toJSONString());
requestPostDoc.queryParam("loadProperties",true); //New changes
responseForNewCaseDocFile=requestPostDoc.post("https://vrh0oox3hl.execute-api.eu-central-1.amazonaws.com/default/");//New changes
filterableRequestSpecification = (FilterableRequestSpecification) requestPostDoc;
filterableRequestSpecification.removeQueryParam("loadProperties");
我在空手道中编写了以下功能文件:
Given url 'https://vrh0oox3hl.execute-api.eu-central-1.amazonaws.com/default/'
And header x-api-key = 'FG6dcYHN9N7PYKfWCUlGo5QGTwZhv2Re1MrDSOTV'
And header Authorization = 'Bearer ' + jwt
And param loadProperties = true
And multipart file info = { read: 'classpath:testData/documentWrite.json', filename: 'documentWrite.json' }
And multipart file Uploading = { read: 'classpath:testData/TextFile.txt', filename: 'TextFile.txt' }
When method post
Then print response
Then status 200
当我执行这个测试时,我得到了 400 个响应代码
状态码为:400,预期:200,响应时间(毫秒):252,url:https://vrh0oox3hl.execute-api.eu-central-1.amazonaws.com/default/?loadProperties=true,响应:
【问题讨论】:
-
多部分很难,因此您需要了解如何准确地形成请求。准备做一些研究并阅读以下内容:github.com/karatelabs/karate/issues/1645#issuecomment-862502881
-
@PeterThomas:所以你能不能告诉我哪里出错了,因为从上面的链接我正在写正确的步骤。我们可以传递多部分字段或其他内容吗?
-
关键是我不能,除非我知道你的服务器期望什么。如果您可以添加适用于您的问题的 cURL 请求,我可以尝试帮助。
-
@PeterThomas : curl --location --request POST 'vrh0oox3hl.execute-api.eu-central-1.amazonaws.com/default' \ --header 'x-api-key: FG6dcYHN9N7PYKfWCUlGo5QGTwZhv2Re1MrDSOTV' \ --header 'Authorization: Bearer tokenkey' \ --形成 'part1-json=@"/D:/Users/bakh/Automation/DMS/karate-DMS/src/test/java/testData/documentWrite.json"' \ --form 'part2-file=@"/D :/Users/bakh/Automation/DMS/karate-DMS/src/test/java/testData/TextFile.txt"'
标签: karate rest-assured