我们有一个WebService,它将formData
键值对作为请求,而不是json。使用openTest
,我们如何通过这些formData
?基本上,我们需要一个代码片段来使用OpenTest
yaml脚本发布formData
。
下面是我们需要使用OpenTest发布的curl命令示例,该命令的内容类型为多部分/表单数据
`
curl --location --request POST 'https://serviceurl.com/getacb'
--form 'userKey=a1b23'
--form 'apiKey=1_ffER_hk6Rb89--2EElfsdeF3'
--form 'secret=Ude+6NIjojo89/gyAB7huGS5'
--form 'targetUID=ulknnk4kjlkj5'
`
我们正在寻找一个示例片段来发布上面的多部分/表单数据。
在将FormData((对象传递给下一个操作之前,您需要自己构建它。
var data = new FormData();
data.append("userKey", "a1b23");
data.append("apiKey", "1_ffER_hk6Rb89--2EElfsdeF3");
data.append("secret", "Ude+6NIjojo89/gyAB7huGS5");
data.append("targetUID", "ulknnk4kjlkj5");
这是对OpenTest API测试YAML进行了一些修改的示例。
description: Example Post based off SO Question
actors:
- actor: ACTOR1
segments:
- segment: 1
actions:
- description: Create a random post ID
script: |
var data = new FormData();
data.append("userKey", "a1b23");
data.append("apiKey", "1_ffER_hk6Rb89--2EElfsdeF3");
data.append("secret", "Ude+6NIjojo89/gyAB7huGS5");
data.append("targetUID", "ulknnk4kjlkj5");
- description: Send a request to getacb
action: org.getopentest.actions.HttpRequest
args:
url: https://serviceurl.com/getacb
headers:
Content-Type: multipart/form-data
verb: POST
body: data
- description: Extract the response's status code and body
script: |
var statusCode = $output.statusCode;
var postInfo = $output.body;
- description: Validate the response status code
script: |
if (statusCode != 201) {
$fail($format(
"We expected the status code to be {0} but it was {1}",
201,
statusCode));
}