From 46ca4511cdbe85c6f861d267f863405b6bff86a6 Mon Sep 17 00:00:00 2001 From: Tam Mullen Date: Thu, 1 Jul 2021 13:02:16 +0100 Subject: [PATCH] Added k6 requests for my account --- .../requests/shopper/my-account.js | 92 +++++++++++++++++++ .../performance/tests/simple-all-requests.js | 12 +++ 2 files changed, 104 insertions(+) create mode 100644 tests/performance/requests/shopper/my-account.js diff --git a/tests/performance/requests/shopper/my-account.js b/tests/performance/requests/shopper/my-account.js new file mode 100644 index 00000000000..f60213b164e --- /dev/null +++ b/tests/performance/requests/shopper/my-account.js @@ -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('

My account

'), + }); + + 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(); +} diff --git a/tests/performance/tests/simple-all-requests.js b/tests/performance/tests/simple-all-requests.js index c367cdafd37..2c8a264038f 100644 --- a/tests/performance/tests/simple-all-requests.js +++ b/tests/performance/tests/simple-all-requests.js @@ -5,6 +5,7 @@ import { SingleProduct } from '../requests/shopper/single-product.js'; import { Cart } from '../requests/shopper/cart.js'; import { CheckoutGuest } from '../requests/shopper/checkout-guest.js'; import { CheckoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; +import { MyAccount } from '../requests/shopper/my-account.js'; export let options = { scenarios: { @@ -55,6 +56,14 @@ export let options = { startTime: '32s', 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(); CheckoutCustomerLogin(); } +export function my_account() { + MyAccount(); +}