2021-06-24 23:42:28 +00:00
|
|
|
import { sleep, check, group } from "k6";
|
|
|
|
import http from "k6/http";
|
|
|
|
import { Trend } from 'k6/metrics';
|
|
|
|
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
|
|
|
|
import { findBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
|
|
|
|
import {
|
|
|
|
base_url,
|
2021-06-30 22:27:41 +00:00
|
|
|
customer_username,
|
|
|
|
customer_password,
|
2021-06-24 23:42:28 +00:00
|
|
|
addresses_customer_billing_first_name,
|
|
|
|
addresses_customer_billing_last_name,
|
|
|
|
addresses_customer_billing_company,
|
|
|
|
addresses_customer_billing_country,
|
|
|
|
addresses_customer_billing_address_1,
|
|
|
|
addresses_customer_billing_address_2,
|
|
|
|
addresses_customer_billing_city,
|
|
|
|
addresses_customer_billing_state,
|
|
|
|
addresses_customer_billing_postcode,
|
|
|
|
addresses_customer_billing_phone,
|
|
|
|
addresses_customer_billing_email,
|
2021-06-30 22:27:41 +00:00
|
|
|
addresses_guest_billing_country,
|
|
|
|
addresses_guest_billing_address_1,
|
|
|
|
addresses_guest_billing_address_2,
|
|
|
|
addresses_guest_billing_city,
|
|
|
|
addresses_guest_billing_state,
|
|
|
|
addresses_guest_billing_postcode,
|
2021-06-24 23:42:28 +00:00
|
|
|
payment_method,
|
|
|
|
think_time_min,
|
|
|
|
think_time_max
|
|
|
|
} from '../../config.js';
|
|
|
|
import {
|
|
|
|
htmlRequestHeader,
|
|
|
|
jsonRequestHeader,
|
|
|
|
allRequestHeader,
|
|
|
|
commonRequestHeaders,
|
|
|
|
commonGetRequestHeaders,
|
|
|
|
commonPostRequestHeaders,
|
|
|
|
commonNonStandardHeaders
|
|
|
|
} from '../../headers.js';
|
|
|
|
|
|
|
|
/* add custom metrics for each step to the standard output */
|
2021-06-30 22:27:41 +00:00
|
|
|
let proceedCheckoutTrend1 = new Trend('wc_get_checkout');
|
|
|
|
let proceedCheckoutTrend2 = new Trend('wc_post_wc-ajax_update_order_review');
|
|
|
|
let checkoutLoginTrend = new Trend('wc_post_checkout');
|
|
|
|
let placeOrderTrend = new Trend('wc_post_wc-ajax_checkout');
|
|
|
|
let orderReceivedTrend1 = new Trend('wc_get_order_received');
|
|
|
|
let orderReceivedTrend2 = new Trend('wc_post_wc-ajax_get_refreshed_fragments');
|
2021-06-24 23:42:28 +00:00
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
export function CheckoutCustomerLogin() {
|
2021-06-24 23:42:28 +00:00
|
|
|
|
|
|
|
let response;
|
2021-06-30 22:27:41 +00:00
|
|
|
let woocommerce_process_checkout_nonce_customer;
|
|
|
|
let woocommerce_login_nonce;
|
|
|
|
let update_order_review_nonce_guest;
|
|
|
|
let update_order_review_nonce_customer;
|
2021-06-24 23:42:28 +00:00
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
group("Proceed to checkout", function () {
|
|
|
|
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
|
|
|
response = http.get(`${base_url}/checkout`, {
|
|
|
|
headers: requestheaders,
|
|
|
|
});
|
|
|
|
proceedCheckoutTrend1.add(response.timings.duration);
|
|
|
|
check(response, {
|
|
|
|
'is status 200': (r) => r.status === 200,
|
|
|
|
"body conatins checkout class": response =>
|
|
|
|
response.body.includes('class="checkout woocommerce-checkout"'),
|
|
|
|
});
|
|
|
|
|
|
|
|
woocommerce_login_nonce = response.html().find("input[name=woocommerce-login-nonce]").first().attr("value");
|
|
|
|
update_order_review_nonce_guest = findBetween(response.body, 'update_order_review_nonce":"', '","apply_coupon_nonce');
|
|
|
|
|
|
|
|
var requestheaders = Object.assign(allRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
|
2021-06-24 23:42:28 +00:00
|
|
|
|
|
|
|
response = http.post(
|
2021-06-30 22:27:41 +00:00
|
|
|
`${base_url}/?wc-ajax=update_order_review`,
|
2021-06-24 23:42:28 +00:00
|
|
|
{
|
2021-06-30 22:27:41 +00:00
|
|
|
security: `${update_order_review_nonce_guest}`,
|
|
|
|
payment_method: `${payment_method}`,
|
|
|
|
country: `${addresses_guest_billing_country}`,
|
|
|
|
state: `${addresses_guest_billing_state}`,
|
|
|
|
postcode: `${addresses_guest_billing_postcode}`,
|
|
|
|
city: `${addresses_guest_billing_city}`,
|
|
|
|
address: `${addresses_guest_billing_address_1}`,
|
|
|
|
address_2: `${addresses_guest_billing_address_2}`,
|
|
|
|
s_country: `${addresses_guest_billing_country}`,
|
|
|
|
s_state: `${addresses_guest_billing_state}`,
|
|
|
|
s_postcode: `${addresses_guest_billing_postcode}`,
|
|
|
|
s_city: `${addresses_guest_billing_city}`,
|
|
|
|
s_address: `${addresses_guest_billing_address_1}`,
|
|
|
|
s_address_2: `${addresses_guest_billing_address_2}`,
|
|
|
|
has_full_address: "true",
|
2021-06-24 23:42:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: requestheaders,
|
|
|
|
}
|
|
|
|
);
|
2021-06-30 22:27:41 +00:00
|
|
|
proceedCheckoutTrend2.add(response.timings.duration);
|
2021-06-24 23:42:28 +00:00
|
|
|
check(response, {
|
|
|
|
'is status 200': (r) => r.status === 200,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
group("Login on checkout", function () {
|
2021-06-24 23:42:28 +00:00
|
|
|
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
response = http.post(`${base_url}/checkout`,
|
|
|
|
{
|
|
|
|
username: `${customer_username}`,
|
|
|
|
password: `${customer_password}`,
|
|
|
|
"woocommerce-login-nonce": `${woocommerce_login_nonce}`,
|
|
|
|
_wp_http_referer: "%2Fcheckout",
|
|
|
|
redirect: `${base_url}/checkout`,
|
|
|
|
login: "Login",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
headers: requestheaders,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
checkoutLoginTrend.add(response.timings.duration);
|
2021-06-24 23:42:28 +00:00
|
|
|
check(response, {
|
2021-06-30 22:27:41 +00:00
|
|
|
'is status 200': (r) => r.status === 200,
|
2021-06-24 23:42:28 +00:00
|
|
|
});
|
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
woocommerce_process_checkout_nonce_customer = response.html().find("input[name=woocommerce-process-checkout-nonce]").first().attr("value");
|
|
|
|
update_order_review_nonce_customer = findBetween(response.body, 'update_order_review_nonce":"', '","apply_coupon_nonce');
|
2021-06-24 23:42:28 +00:00
|
|
|
|
|
|
|
var requestheaders = Object.assign(allRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
|
|
|
response = http.post(
|
|
|
|
`${base_url}/?wc-ajax=update_order_review`,
|
|
|
|
{
|
2021-06-30 22:27:41 +00:00
|
|
|
security: `${update_order_review_nonce_customer}`,
|
2021-06-24 23:42:28 +00:00
|
|
|
payment_method: `${payment_method}`,
|
|
|
|
country: `${addresses_customer_billing_country}`,
|
|
|
|
state: `${addresses_customer_billing_state}`,
|
|
|
|
postcode: `${addresses_customer_billing_postcode}`,
|
|
|
|
city: `${addresses_customer_billing_city}`,
|
|
|
|
address: `${addresses_customer_billing_address_1}`,
|
|
|
|
address_2: `${addresses_customer_billing_address_2}`,
|
|
|
|
s_country: `${addresses_customer_billing_country}`,
|
|
|
|
s_state: `${addresses_customer_billing_state}`,
|
|
|
|
s_postcode: `${addresses_customer_billing_postcode}`,
|
|
|
|
s_city: `${addresses_customer_billing_city}`,
|
|
|
|
s_address: `${addresses_customer_billing_address_1}`,
|
|
|
|
s_address_2: `${addresses_customer_billing_address_2}`,
|
|
|
|
has_full_address: "true",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: requestheaders,
|
|
|
|
}
|
|
|
|
);
|
2021-06-30 22:27:41 +00:00
|
|
|
proceedCheckoutTrend2.add(response.timings.duration);
|
2021-06-24 23:42:28 +00:00
|
|
|
check(response, {
|
2021-06-30 22:27:41 +00:00
|
|
|
'is status 200': (r) => r.status === 200,
|
2021-06-24 23:42:28 +00:00
|
|
|
});
|
2021-06-30 22:27:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
2021-06-24 23:42:28 +00:00
|
|
|
|
2021-06-30 22:27:41 +00:00
|
|
|
group("Place Order", function () {
|
2021-06-24 23:42:28 +00:00
|
|
|
var requestheaders = Object.assign(jsonRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
|
|
|
response = http.post(
|
|
|
|
`${base_url}/?wc-ajax=checkout`,
|
|
|
|
{
|
|
|
|
billing_first_name: `${addresses_customer_billing_first_name}`,
|
|
|
|
billing_last_name: `${addresses_customer_billing_last_name}`,
|
|
|
|
billing_company: `${addresses_customer_billing_company}`,
|
|
|
|
billing_country: `${addresses_customer_billing_country}`,
|
|
|
|
billing_address_1: `${addresses_customer_billing_address_1}`,
|
|
|
|
billing_address_2: `${addresses_customer_billing_address_2}`,
|
|
|
|
billing_city: `${addresses_customer_billing_city}`,
|
|
|
|
billing_state: `${addresses_customer_billing_state}`,
|
|
|
|
billing_postcode: `${addresses_customer_billing_postcode}`,
|
|
|
|
billing_phone: `${addresses_customer_billing_phone}`,
|
|
|
|
billing_email: `${addresses_customer_billing_email}`,
|
|
|
|
order_comments: "",
|
|
|
|
payment_method: `${payment_method}`,
|
2021-06-30 22:27:41 +00:00
|
|
|
"woocommerce-process-checkout-nonce": `${woocommerce_process_checkout_nonce_customer}`,
|
2021-06-24 23:42:28 +00:00
|
|
|
_wp_http_referer: "%2F%3Fwc-ajax%3Dupdate_order_review",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: requestheaders,
|
|
|
|
}
|
|
|
|
);
|
2021-06-30 22:27:41 +00:00
|
|
|
placeOrderTrend.add(response.timings.duration);
|
2021-06-24 23:42:28 +00:00
|
|
|
check(response, {
|
2021-06-30 22:27:41 +00:00
|
|
|
'is status 200': (r) => r.status === 200,
|
|
|
|
"body conatins order-received": response =>
|
|
|
|
response.body.includes('order-received'),
|
2021-06-24 23:42:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
|
|
|
|
|
|
|
group("Order received", function () {
|
|
|
|
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
|
|
|
response = http.get(
|
|
|
|
`${base_url}/checkout/order-received/`,
|
|
|
|
{
|
|
|
|
headers: requestheaders,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
check(response, {
|
|
|
|
"body contains 'Thank you. Your order has been received.'": response =>
|
|
|
|
response.body.includes("Thank you. Your order has been received."),
|
|
|
|
});
|
|
|
|
orderReceivedTrend1.add(response.timings.duration);
|
|
|
|
|
|
|
|
var requestheaders = Object.assign(allRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
|
|
|
|
|
|
|
|
response = http.post(
|
|
|
|
`${base_url}/?wc-ajax=get_refreshed_fragments`,
|
|
|
|
{
|
|
|
|
headers: requestheaders,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
orderReceivedTrend2.add(response.timings.duration);
|
|
|
|
check(response, {
|
2021-06-30 22:27:41 +00:00
|
|
|
'is status 200': (r) => r.status === 200,
|
2021-06-24 23:42:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function () {
|
2021-06-30 22:27:41 +00:00
|
|
|
CheckoutCustomerLogin();
|
2021-06-24 23:42:28 +00:00
|
|
|
}
|