-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
html_form_post.js
30 lines (27 loc) · 1.01 KB
/
html_form_post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import http from "k6/http";
import { check } from "k6";
// Our form data, to be URL-encoded and POSTed
const form_data = {
name: "Test Name",
telephone: "123456789",
email: "[email protected]",
comment: "Hello world!",
topping: [
'onion',
'bacon',
'cheese'
]
};
export default function() {
// Passing an object as the data parameter will automatically form-urlencode it
let res = http.post("http://httpbin.org/post", form_data);
// Verify response
check(res, {
"status is 200": (r) => r.status === 200,
"has correct name": (r) => r.json().form.name === form_data.name,
"has correct telephone number": (r) => r.json().form.telephone === form_data.telephone,
"has correct email": (r) => r.json().form.email === form_data.email,
"has correct comment": (r) => r.json().form.comment === form_data.comment,
"has correct toppings": (r) => JSON.stringify(r.json().form.topping) === JSON.stringify(form_data.topping)
});
}