forked from grafana/k6-example-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitCheckout.js
113 lines (102 loc) · 3.31 KB
/
submitCheckout.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { group, check, fail } from "k6";
import http, { request } from "k6/http";
import jsonpath from "https://jslib.k6.io/jsonpath/1.0.2/index.js";
export function submitCheckout() {
let response;
group("Submit Checkout", function () {
response = http.post(
"http://ecommerce.test.k6.io/?wc-ajax=checkout",
{
billing_first_name: "k6",
billing_last_name: "Test",
billing_company: "",
billing_country: "US",
billing_address_1: "Street Address 1",
billing_address_2: "",
billing_city: "Frisco",
billing_state: "CO",
billing_postcode: "80443",
billing_phone: "7201234567",
billing_email: "[email protected]",
order_comments: "",
payment_method: "cod",
"woocommerce-process-checkout-nonce": vars["checkoutToken"],
_wp_http_referer: "/?wc-ajax=update_order_review",
},
{
headers: {
accept: "application/json, text/javascript, */*; q=0.01",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en;q=0.9",
connection: "keep-alive",
"content-type":
"application/x-www-form-urlencoded;type=content-type;mimeType=application/x-www-form-urlencoded",
host: "ecommerce.test.k6.io",
origin: "http://ecommerce.test.k6.io",
"x-requested-with": "XMLHttpRequest",
},
}
);
let result;
try {
result = jsonpath.query(
response.json(),
"$['result']"
)[0];
} catch (err) {
// not JSON most likely, so print debug to console
console.error(err);
console.log(response.body);
}
check(result, {
'checkout success': (r) => r === 'success'
});
vars["redirectUrl"] = jsonpath.query(
response.json(),
"$['redirect']"
)[0];
if (!vars["redirectUrl"]) {
fail(`Checkout failed: no redirect URL in response:\n${response.body}`);
}
if (isDebug) {
console.log("Checkout redirect URL: " + vars["redirectUrl"]);
}
response = http.get(
// "http://ecommerce.test.k6.io/checkout/order-received/63/?key=wc_order_YIi1bD2E9kzOO",
vars["redirectUrl"],
{
tags: {
name: "http://ecommerce.test.k6.io/checkout/order-received/"
},
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en;q=0.9",
connection: "keep-alive",
host: "ecommerce.test.k6.io",
"upgrade-insecure-requests": "1",
},
}
);
response = http.post(
"http://ecommerce.test.k6.io/?wc-ajax=get_refreshed_fragments",
{
time: "1613672584353",
},
{
headers: {
accept: "*/*",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en;q=0.9",
connection: "keep-alive",
"content-type":
"application/x-www-form-urlencoded;type=content-type;mimeType=application/x-www-form-urlencoded",
host: "ecommerce.test.k6.io",
origin: "http://ecommerce.test.k6.io",
"x-requested-with": "XMLHttpRequest",
},
}
);
});
}