woocommerce/tests/performance/requests/merchant/wp-login.js

92 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-07-01 13:53:13 +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 13:53:13 +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,
admin_username,
admin_password,
think_time_min,
think_time_max,
} from "../../config.js";
2021-07-01 13:53:13 +00:00
import {
2021-07-13 14:54:23 +00:00
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders,
} from "../../headers.js";
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
// Custom metrics to add to standard results output.
let wpLoginTrend = new Trend("wc_get_wp_login");
let wpLoginWPAdminTrend = new Trend("wc_post_wp_login");
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
export function wpLogin() {
let response;
let testcookie;
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
group("Login Page", function () {
var requestHeaders = Object.assign(
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders
);
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
response = http.get(`${base_url}/wp-login.php`, {
headers: requestHeaders,
});
wpLoginTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
"body conatins: 'Log in' title": (response) =>
response.body.includes("<title>Log In"),
});
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
// Correlate cookie value for use in subsequent requests.
testcookie = response
.html()
.find("input[name=testcookie]")
.first()
.attr("value");
});
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
group("Login to WP Admin", function () {
var requestHeaders = Object.assign(
htmlRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonNonStandardHeaders
);
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
response = http.post(
`${base_url}/wp-login.php`,
{
log: `${admin_username}`,
pwd: `${admin_password}`,
"wp-submit": "Log%20In",
redirect_to: `${base_url}/wp-admin`,
testcookie: `${testcookie}`,
},
{
headers: {
headers: requestHeaders,
},
}
);
wpLoginWPAdminTrend.add(response.timings.duration);
check(response, {
"is status 200": (r) => r.status === 200,
"body conatins: wp-admin 'Dashboard' header": (response) =>
response.body.includes("<h1>Dashboard</h1>"),
});
});
2021-07-01 13:53:13 +00:00
2021-07-13 14:54:23 +00:00
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
}
2021-07-01 13:53:13 +00:00
export default function () {
2021-07-13 14:54:23 +00:00
wpLogin();
}