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 { base_url, admin_username, admin_password, think_time_min, think_time_max } from '../../config.js'; import { htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders } from '../../headers.js'; /* add custom metrics for each step to the standard output */ let wpLoginTrend = new Trend('wc_get_wp_login'); let wpLoginWPAdminTrend = new Trend('wc_post_wp_login'); export function WPLogin() { let response; let testcookie; group("Login Page", function () { var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders) 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 login title": response => response.body.includes('Log In'), }); testcookie = response.html().find("input[name=testcookie]").first().attr("value"); }); sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`)); group("Login to WP Admin", function () { var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders) 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>'), }); }); } export default function () { WPLogin(); }