在将 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 testing 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));
}