Reputation: 31
We have a WebService which takes formData
key-value pair as the request instead of json. Using openTest
how can we pass these formData
? Basically we need a code snippet to post the formData
using OpenTest
yaml script.
Below is the sample curl command which we need to post using OpenTest which has Content-Type as multipart/form-data
`
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'
`
We are looking for a sample snippet to post the above multipart/form-data.
Upvotes: 3
Views: 387
Reputation: 540
You'll need to build the FormData() object yourself before passing it to the next action.
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");
This is the sample with some modifications from 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));
}
Upvotes: 0