Added k6 requests for my account

This commit is contained in:
Tam Mullen 2021-07-01 13:02:16 +01:00
parent 093ce67fcc
commit 46ca4511cd
2 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,92 @@
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,
customer_username,
customer_password,
think_time_min,
think_time_max
} from '../../config.js';
import {
htmlRequestHeader,
allRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonPostRequestHeaders,
commonNonStandardHeaders
} from '../../headers.js';
/* add custom metrics for each step to the standard 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');
export function MyAccount() {
let response;
let woocommerce_login_nonce;
group("My Account", function () {
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
response = http.get(`${base_url}/my-account`,
{
headers: requestheaders,
});
myAccountTrend.add(response.timings.duration);
check(response, {
'is status 200': (r) => r.status === 200,
"body conatins My account title": response =>
response.body.includes('<h1 class="entry-title">My account</h1>'),
});
woocommerce_login_nonce = response.html().find("input[name=woocommerce-login-nonce]").first().attr("value");
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
group("My Account Login", function () {
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
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 conatins My account welcome": response =>
response.body.includes('From your account dashboard you can view'),
});
var requestheaders = Object.assign(allRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
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,
});
});
}
export default function () {
MyAccount();
}

View File

@ -5,6 +5,7 @@ import { SingleProduct } from '../requests/shopper/single-product.js';
import { Cart } from '../requests/shopper/cart.js'; import { Cart } from '../requests/shopper/cart.js';
import { CheckoutGuest } from '../requests/shopper/checkout-guest.js'; import { CheckoutGuest } from '../requests/shopper/checkout-guest.js';
import { CheckoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; import { CheckoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js';
import { MyAccount } from '../requests/shopper/my-account.js';
export let options = { export let options = {
scenarios: { scenarios: {
@ -55,6 +56,14 @@ export let options = {
startTime: '32s', startTime: '32s',
exec: 'checkout_customer_login', exec: 'checkout_customer_login',
}, },
myAccount: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 1,
maxDuration: '50s',
startTime: '48s',
exec: 'my_account',
},
}, },
}; };
@ -78,3 +87,6 @@ export function checkout_customer_login() {
Cart(); Cart();
CheckoutCustomerLogin(); CheckoutCustomerLogin();
} }
export function my_account() {
MyAccount();
}