Added product search request

This commit is contained in:
Tam Mullen 2021-07-01 12:11:26 +01:00
parent 07ab1e8725
commit 093ce67fcc
4 changed files with 177 additions and 38 deletions

View File

@ -33,6 +33,7 @@ export const payment_method = 'cod';
export const product_sku = __ENV.P_SKU || 'woo-beanie'; export const product_sku = __ENV.P_SKU || 'woo-beanie';
export const product_url = __ENV.P_URL || 'beanie'; export const product_url = __ENV.P_URL || 'beanie';
export const product_id = __ENV.P_ID || '13'; export const product_id = __ENV.P_ID || '13';
export const product_search_term = __ENV.P_TERM || 'beanie';
export const think_time_min = '1'; export const think_time_min = '1';
export const think_time_max = '4'; export const think_time_max = '4';

View File

@ -0,0 +1,70 @@
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,
product_sku,
product_id,
think_time_min,
think_time_max
} from '../../config.js';
import {
htmlRequestHeader,
jsonRequestHeader,
commonRequestHeaders,
commonGetRequestHeaders,
commonPostRequestHeaders,
commonNonStandardHeaders
} from '../../headers.js';
/* add custom metrics for each step to the standard output */
let addToCartTrend = new Trend('wc_post_wc-ajax_add_to_cart');
let viewCartTrend = new Trend('wc_get_cart');
export function Cart() {
let response;
group("Product Page Add to cart", function () {
var requestheaders = Object.assign(jsonRequestHeader, commonRequestHeaders, commonPostRequestHeaders, commonNonStandardHeaders)
response = http.post(
`${base_url}/?wc-ajax=add_to_cart`,
{
product_sku: `${product_sku}`,
product_id: `${product_id}`,
quantity: "1",
},
{
headers: requestheaders,
}
);
addToCartTrend.add(response.timings.duration);
check(response, {
'is status 200': (r) => r.status === 200,
});
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
group("View Cart", function () {
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
response = http.get(`${base_url}/cart`, {
headers: requestheaders,
});
viewCartTrend.add(response.timings.duration);
check(response, {
'is status 200': (r) => r.status === 200,
"body does not contain 'your cart is currently empty'": response =>
!response.body.includes("Your cart is currently empty."),
});
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
}
export default function () {
Cart();
}

View File

@ -0,0 +1,44 @@
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,
product_search_term,
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 searchProductTrend = new Trend('wc_get_search_product');
export function SearchProduct() {
let response;
group("Search Product", function () {
var requestheaders = Object.assign(htmlRequestHeader, commonRequestHeaders, commonGetRequestHeaders, commonNonStandardHeaders)
response = http.get(`${base_url}/?s=${product_search_term}&post_type=product`, {
headers: requestheaders,
});
searchProductTrend.add(response.timings.duration);
check(response, {
'is status 200': (r) => r.status === 200,
"body conatins search results title": response =>
response.body.includes("Search results:"),
});
});
sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`));
}
export default function () {
SearchProduct();
}

View File

@ -1,5 +1,6 @@
import { HomePage } from '../requests/shopper/home.js'; import { HomePage } from '../requests/shopper/home.js';
import { ShopPage } from '../requests/shopper/shop-page.js'; import { ShopPage } from '../requests/shopper/shop-page.js';
import { SearchProduct } from '../requests/shopper/search-product.js';
import { SingleProduct } from '../requests/shopper/single-product.js'; 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';
@ -22,21 +23,37 @@ export let options = {
startTime: '4s', startTime: '4s',
exec: 'shop_page', exec: 'shop_page',
}, },
singleProduct: { searchProduct: {
executor: 'per-vu-iterations', executor: 'per-vu-iterations',
vus: 1, vus: 1,
iterations: 1, iterations: 1,
maxDuration: '10s', maxDuration: '10s',
startTime: '8s', startTime: '8s',
exec: 'search_product',
},
singleProduct: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 1,
maxDuration: '10s',
startTime: '12s',
exec: 'single_product', exec: 'single_product',
}, },
checkoutFlow: { checkoutGuest: {
executor: 'per-vu-iterations', executor: 'per-vu-iterations',
vus: 1, vus: 1,
iterations: 1, iterations: 1,
maxDuration: '50s', maxDuration: '50s',
startTime: '16s', startTime: '16s',
exec: 'checkout', exec: 'checkout_guest',
},
checkoutCustomerLogin: {
executor: 'per-vu-iterations',
vus: 1,
iterations: 1,
maxDuration: '50s',
startTime: '32s',
exec: 'checkout_customer_login',
}, },
}, },
}; };
@ -47,10 +64,17 @@ export function home_page() {
export function shop_page() { export function shop_page() {
ShopPage(); ShopPage();
} }
export function search_product() {
SearchProduct();
}
export function single_product() { export function single_product() {
SingleProduct(); SingleProduct();
} }
export function checkout() { export function checkout_guest() {
Cart(); Cart();
CheckoutGuest(); CheckoutGuest();
} }
export function checkout_customer_login() {
Cart();
CheckoutCustomerLogin();
}