woocommerce/tests/performance/requests/shopper/my-account.js

114 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-07-01 12:02:16 +00:00
import { sleep, check, group } from "k6";
import http from "k6/http";
2021-07-13 14:54:23 +00:00
import { Trend } from "k6/metrics";
2021-07-01 12:02:16 +00:00
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
import {
2021-07-13 14:54:23 +00:00
base_url,
customer_username,
customer_password,
think_time_min,
think_time_max,
} from "../../config.js";
2021-07-01 12:02:16 +00:00
import {
2021-07-13 14:54:23 +00:00
htmlRequestHeader,
allRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonPostRequestHeaders,
commonNonStandardHeaders,
} from "../../headers.js";
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
// Custom metrics to add to standard results output.
let myAccountTrend = new Trend("wc_get_myaccount");
let myAccountLoginTrend = new Trend("wc_post_myaccount");
let myAccountLoginTrend2 = new Trend("wc_post_wc-ajax_get_refreshed_fragments");
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
export function myAccount() {
let response;
let woocommerce_login_nonce;
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
group("My Account", function () {
var requestHeaders = Object.assign({},
2021-07-13 14:54:23 +00:00
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders
);
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
response = http.get(`${base_url}/my-account`, {
headers: requestHeaders,
});
myAccountTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
"body contains: 'My account' title": (response) =>
2021-07-13 14:54:23 +00:00
response.body.includes(
'<h1 class="entry-title">My account</h1>'
),
});
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
// Correlate nonce value for use in subsequent requests.
woocommerce_login_nonce = response
.html()
.find("input[name=woocommerce-login-nonce]")
.first()
.attr("value");
});
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
group("My Account Login", function () {
var requestHeaders = Object.assign({},
2021-07-13 14:54:23 +00:00
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders
);
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
response = http.post(
`${base_url}/my-account`,
{
username: `${customer_username}`,
password: `${customer_password}`,
"woocommerce-login-nonce": `${woocommerce_login_nonce}`,
_wp_http_referer: "/my-account",
login: "Log%20in",
},
{
headers: {
headers: requestHeaders,
},
}
);
myAccountLoginTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
"body contains: my account welcome message": (response) =>
2021-07-13 14:54:23 +00:00
response.body.includes(
"From your account dashboard you can view"
),
});
2021-07-01 12:02:16 +00:00
var requestHeaders = Object.assign({},
2021-07-13 14:54:23 +00:00
allRequestHeader,
commonRequestHeaders,
commonPostRequestHeaders,
commonNonStandardHeaders
);
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
response = http.post(`${base_url}/?wc-ajax=get_refreshed_fragments`, {
headers: requestHeaders,
});
myAccountLoginTrend2.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
});
});
2021-07-01 12:02:16 +00:00
2021-07-13 14:54:23 +00:00
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
2021-07-01 12:02:16 +00:00
}
export default function () {
2021-07-13 14:54:23 +00:00
myAccount();
2021-07-01 12:02:16 +00:00
}