[k6 tests] Fix broken perf tests - updated page titles (#51173)

This commit is contained in:
Adrian Moldovan 2024-09-05 18:53:00 +01:00 committed by GitHub
parent d2fb60a5d1
commit 61d41adf79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 435 additions and 429 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev

View File

@ -2,6 +2,9 @@
export const base_url = __ENV.URL || 'http://localhost:8086'; export const base_url = __ENV.URL || 'http://localhost:8086';
export const base_host = __ENV.HOST || 'localhost:8086'; export const base_host = __ENV.HOST || 'localhost:8086';
export const STORE_NAME = __ENV.STORE_NAME || 'WooCommerce Core E2E Test Suite';
export const FOOTER_TEXT = 'Built with WooCommerce';
export const admin_username = __ENV.A_USER || 'admin'; export const admin_username = __ENV.A_USER || 'admin';
export const admin_password = __ENV.A_PW || 'password'; export const admin_password = __ENV.A_PW || 'password';
export const admin_acc_login = __ENV.A_ACC_LOGIN || false; export const admin_acc_login = __ENV.A_ACC_LOGIN || false;

View File

@ -1,73 +1,76 @@
/**
* Internal dependencies
*/
import { base_host, base_url } from './config.js'; import { base_host, base_url } from './config.js';
const htmlRequestHeader = { const htmlRequestHeader = {
accept: accept:
'text/html,application/xhtml+xml,application/xml;' + 'text/html,application/xhtml+xml,application/xml;' +
'q=0.9,image/avif,image/webp,image/apng,*/*;' + 'q=0.9,image/avif,image/webp,image/apng,*/*;' +
'q=0.8,application/signed-exchange;v=b3;q=0.9' 'q=0.8,application/signed-exchange;v=b3;q=0.9',
}; };
const jsonRequestHeader = { const jsonRequestHeader = {
accept: 'application/json, text/javascript, */*; q=0.01' accept: 'application/json, text/javascript, */*; q=0.01',
}; };
const jsonAPIRequestHeader = { const jsonAPIRequestHeader = {
accept: 'application/json, */*;q=0.1' accept: 'application/json, */*;q=0.1',
}; };
const allRequestHeader = { const allRequestHeader = {
accept: '*//*' accept: '*//*',
}; };
const commonRequestHeaders = { const commonRequestHeaders = {
'accept-language': 'en-US,en;q=0.9' 'accept-language': 'en-US,en;q=0.9',
}; };
const commonGetRequestHeaders = { const commonGetRequestHeaders = {
connection: 'keep-alive', connection: 'keep-alive',
host: `${base_host}`, host: `${ base_host }`,
'sec-fetch-dest': 'document', 'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate', 'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1', 'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1' 'upgrade-insecure-requests': '1',
}; };
const commonAPIGetRequestHeaders = { const commonAPIGetRequestHeaders = {
connection: 'keep-alive', connection: 'keep-alive',
host: `${base_host}`, host: `${ base_host }`,
'sec-fetch-dest': 'empty', 'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors', 'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
}; };
const contentTypeRequestHeader = { const contentTypeRequestHeader = {
'content-type': 'application/x-www-form-urlencoded' 'content-type': 'application/x-www-form-urlencoded',
}; };
const commonPostRequestHeaders = { const commonPostRequestHeaders = {
origin: `${base_url}`, origin: `${ base_url }`,
'sec-fetch-dest': 'empty', 'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors', 'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin', 'sec-fetch-site': 'same-origin',
'x-requested-with': 'XMLHttpRequest' 'x-requested-with': 'XMLHttpRequest',
}; };
const commonNonStandardHeaders = { const commonNonStandardHeaders = {
'sec-ch-ua': 'sec-ch-ua':
'" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"',
'sec-ch-ua-mobile': '?0' 'sec-ch-ua-mobile': '?0',
}; };
export { export {
htmlRequestHeader, htmlRequestHeader,
jsonRequestHeader, jsonRequestHeader,
jsonAPIRequestHeader, jsonAPIRequestHeader,
allRequestHeader, allRequestHeader,
commonRequestHeaders, commonRequestHeaders,
commonGetRequestHeaders, commonGetRequestHeaders,
commonAPIGetRequestHeaders, commonAPIGetRequestHeaders,
contentTypeRequestHeader, contentTypeRequestHeader,
commonPostRequestHeaders, commonPostRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
}; };

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -65,17 +64,15 @@ if ( hpos_status === true ) {
} else { } else {
admin_new_order_base = 'post-new.php?post_type=shop_order'; admin_new_order_base = 'post-new.php?post_type=shop_order';
admin_update_order_base = 'post.php'; admin_update_order_base = 'post.php';
admin_new_order_assert = 'Add new order</h1>'; admin_new_order_assert = 'Add new order';
admin_open_order_assert = 'Edit order</h1>'; admin_open_order_assert = 'Edit order</h1>';
admin_created_order_assert = 'Order updated.'; admin_created_order_assert = 'Order updated.';
admin_update_order_assert = 'Order updated.'; admin_update_order_assert = 'Order updated.';
} }
const date = new Date(); const global_order_date = new Date().toJSON().slice( 0, 10 );
const order_date = date.toJSON().slice( 0, 10 );
export function addOrder( includeTests = {} ) { export function addOrder( includeTests = {} ) {
let response;
let ajax_nonce_add_meta; let ajax_nonce_add_meta;
let wpnonce; let wpnonce;
let closed_postboxes_nonce; let closed_postboxes_nonce;
@ -87,7 +84,8 @@ export function addOrder( includeTests = {} ) {
let api_x_wp_nonce; let api_x_wp_nonce;
let apiNonceHeader; let apiNonceHeader;
let heartbeat_nonce; let heartbeat_nonce;
let includedTests = Object.assign( { const includedTests = Object.assign(
{
create: true, create: true,
heartbeat: true, heartbeat: true,
open: true, open: true,
@ -106,7 +104,7 @@ export function addOrder( includeTests = {} ) {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( const response = http.get(
`${ base_url }/wp-admin/${ admin_new_order_base }`, `${ base_url }/wp-admin/${ admin_new_order_base }`,
{ {
headers: requestHeaders, headers: requestHeaders,
@ -115,8 +113,8 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Add new order' header": ( response ) => "body contains: 'Add new order' header": ( r ) =>
response.body.includes( `${ admin_new_order_assert }` ), r.body.includes( `${ admin_new_order_assert }` ),
} ); } );
// Correlate nonce values for use in subsequent requests. // Correlate nonce values for use in subsequent requests.
@ -190,18 +188,18 @@ export function addOrder( includeTests = {} ) {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( const tasksResponse = http.get(
`${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`,
{ {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, tags: { name: 'Merchant - wc-admin/onboarding/tasks?' },
} }
); );
check( response, { check( tasksResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
response = http.get( const notesResponse = http.get(
`${ base_url }/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` + `${ base_url }/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` +
`type=error%2Cupdate&status=unactioned&_locale=user`, `type=error%2Cupdate&status=unactioned&_locale=user`,
{ {
@ -209,11 +207,11 @@ export function addOrder( includeTests = {} ) {
tags: { name: 'Merchant - wc-analytics/admin/notes?' }, tags: { name: 'Merchant - wc-analytics/admin/notes?' },
} }
); );
check( response, { check( notesResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
response = http.get( const optionsResponse = http.get(
`${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`,
{ {
headers: requestHeaders, headers: requestHeaders,
@ -222,7 +220,7 @@ export function addOrder( includeTests = {} ) {
}, },
} }
); );
check( response, { check( optionsResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );
@ -239,7 +237,7 @@ export function addOrder( includeTests = {} ) {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/wp-admin/admin-ajax.php`, `${ base_url }/wp-admin/admin-ajax.php`,
`_nonce=${ heartbeat_nonce }&action=heartbeat&has_focus=true&interval=15&screen_id=shop_order`, `_nonce=${ heartbeat_nonce }&action=heartbeat&has_focus=true&interval=15&screen_id=shop_order`,
{ {
@ -252,7 +250,9 @@ export function addOrder( includeTests = {} ) {
} ); } );
} ); } );
sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); sleep(
randomIntBetween( `${ think_time_min }`, `${ think_time_max }` )
);
} }
if ( includedTests.create ) { if ( includedTests.create ) {
@ -266,13 +266,18 @@ export function addOrder( includeTests = {} ) {
commonNonStandardHeaders commonNonStandardHeaders
); );
const date = new Date(); const order_date = new Date().toJSON().slice( 0, 10 );
const order_date = date.toJSON().slice( 0, 10 );
const orderParams = new URLSearchParams( [ const orderParams = new URLSearchParams( [
[ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ],
[ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], '_billing_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_billing_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_city', `${ addresses_guest_billing_city }` ],
[ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ],
[ '_billing_country', `${ addresses_guest_billing_country }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ],
@ -281,12 +286,24 @@ export function addOrder( includeTests = {} ) {
'_billing_first_name', '_billing_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], [
'_billing_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_billing_phone', `${ addresses_guest_billing_phone }` ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ],
[ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], [
'_billing_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_billing_state', `${ addresses_guest_billing_state }` ], [ '_billing_state', `${ addresses_guest_billing_state }` ],
[ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], '_shipping_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_shipping_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_city', `${ addresses_guest_billing_city }` ],
[ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ],
[ '_shipping_country', `${ addresses_guest_billing_country }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ],
@ -294,9 +311,15 @@ export function addOrder( includeTests = {} ) {
'_shipping_first_name', '_shipping_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], [
'_shipping_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_shipping_phone', `${ addresses_guest_billing_phone }` ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ],
[ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], [
'_shipping_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_shipping_state', `${ addresses_guest_billing_state }` ],
[ '_payment_method', `${ payment_method }` ], [ '_payment_method', `${ payment_method }` ],
[ '_transaction_id', '' ], [ '_transaction_id', '' ],
@ -337,8 +360,14 @@ export function addOrder( includeTests = {} ) {
const hposOrderParams = new URLSearchParams( [ const hposOrderParams = new URLSearchParams( [
[ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ],
[ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], '_billing_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_billing_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_city', `${ addresses_guest_billing_city }` ],
[ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ],
[ '_billing_country', `${ addresses_guest_billing_country }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ],
@ -347,12 +376,24 @@ export function addOrder( includeTests = {} ) {
'_billing_first_name', '_billing_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], [
'_billing_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_billing_phone', `${ addresses_guest_billing_phone }` ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ],
[ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], [
'_billing_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_billing_state', `${ addresses_guest_billing_state }` ], [ '_billing_state', `${ addresses_guest_billing_state }` ],
[ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], '_shipping_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_shipping_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_city', `${ addresses_guest_billing_city }` ],
[ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ],
[ '_shipping_country', `${ addresses_guest_billing_country }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ],
@ -360,9 +401,15 @@ export function addOrder( includeTests = {} ) {
'_shipping_first_name', '_shipping_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], [
'_shipping_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_shipping_phone', `${ addresses_guest_billing_phone }` ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ],
[ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], [
'_shipping_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_shipping_state', `${ addresses_guest_billing_state }` ],
[ '_payment_method', `${ payment_method }` ], [ '_payment_method', `${ payment_method }` ],
[ '_transaction_id', '' ], [ '_transaction_id', '' ],
@ -397,7 +444,7 @@ export function addOrder( includeTests = {} ) {
admin_update_order_params = orderParams.toString(); admin_update_order_params = orderParams.toString();
} }
response = http.post( const response = http.post(
`${ base_url }/wp-admin/${ admin_update_order }`, `${ base_url }/wp-admin/${ admin_update_order }`,
admin_update_order_params.toString(), admin_update_order_params.toString(),
{ {
@ -407,14 +454,16 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Edit order' header": ( response ) => "body contains: 'Edit order' header": ( r ) =>
response.body.includes( `${ admin_open_order_assert }` ), r.body.includes( `${ admin_open_order_assert }` ),
"body contains: 'Order updated' confirmation": ( response ) => "body contains: 'Order updated' confirmation": ( r ) =>
response.body.includes( `${ admin_created_order_assert }` ), r.body.includes( `${ admin_created_order_assert }` ),
} ); } );
} ); } );
sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); sleep(
randomIntBetween( `${ think_time_min }`, `${ think_time_max }` )
);
} }
if ( includedTests.open ) { if ( includedTests.open ) {
@ -433,7 +482,7 @@ export function addOrder( includeTests = {} ) {
admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`;
} }
response = http.get( const response = http.get(
`${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`,
{ {
headers: requestHeaders, headers: requestHeaders,
@ -442,12 +491,14 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Edit order' header": ( response ) => "body contains: 'Edit order' header": ( r ) =>
response.body.includes( `${ admin_open_order_assert }` ), r.body.includes( `${ admin_open_order_assert }` ),
} ); } );
} ); } );
sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); sleep(
randomIntBetween( `${ think_time_min }`, `${ think_time_max }` )
);
} }
if ( includedTests.update ) { if ( includedTests.update ) {
@ -463,8 +514,14 @@ export function addOrder( includeTests = {} ) {
const orderParams = new URLSearchParams( [ const orderParams = new URLSearchParams( [
[ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ],
[ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], '_billing_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_billing_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_city', `${ addresses_guest_billing_city }` ],
[ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ],
[ '_billing_country', `${ addresses_guest_billing_country }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ],
@ -473,12 +530,24 @@ export function addOrder( includeTests = {} ) {
'_billing_first_name', '_billing_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], [
'_billing_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_billing_phone', `${ addresses_guest_billing_phone }` ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ],
[ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], [
'_billing_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_billing_state', `${ addresses_guest_billing_state }` ], [ '_billing_state', `${ addresses_guest_billing_state }` ],
[ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], '_shipping_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_shipping_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_city', `${ addresses_guest_billing_city }` ],
[ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ],
[ '_shipping_country', `${ addresses_guest_billing_country }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ],
@ -486,9 +555,15 @@ export function addOrder( includeTests = {} ) {
'_shipping_first_name', '_shipping_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], [
'_shipping_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_shipping_phone', `${ addresses_guest_billing_phone }` ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ],
[ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], [
'_shipping_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_shipping_state', `${ addresses_guest_billing_state }` ],
[ '_payment_method', `${ payment_method }` ], [ '_payment_method', `${ payment_method }` ],
[ '_transaction_id', '' ], [ '_transaction_id', '' ],
@ -503,7 +578,7 @@ export function addOrder( includeTests = {} ) {
[ 'metakeyinput', '' ], [ 'metakeyinput', '' ],
[ 'metakeyselect', '%23NONE%23' ], [ 'metakeyselect', '%23NONE%23' ],
[ 'metavalue', '' ], [ 'metavalue', '' ],
[ 'order_date', `${ order_date }` ], [ 'order_date', `${ global_order_date }` ],
[ 'order_date_hour', '01' ], [ 'order_date_hour', '01' ],
[ 'order_date_minute', '01' ], [ 'order_date_minute', '01' ],
[ 'order_date_second', '01' ], [ 'order_date_second', '01' ],
@ -528,8 +603,14 @@ export function addOrder( includeTests = {} ) {
const hposOrderParams = new URLSearchParams( [ const hposOrderParams = new URLSearchParams( [
[ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ],
[ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], '_billing_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_billing_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_billing_city', `${ addresses_guest_billing_city }` ], [ '_billing_city', `${ addresses_guest_billing_city }` ],
[ '_billing_company', `${ addresses_guest_billing_company }` ], [ '_billing_company', `${ addresses_guest_billing_company }` ],
[ '_billing_country', `${ addresses_guest_billing_country }` ], [ '_billing_country', `${ addresses_guest_billing_country }` ],
@ -538,12 +619,24 @@ export function addOrder( includeTests = {} ) {
'_billing_first_name', '_billing_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], [
'_billing_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_billing_phone', `${ addresses_guest_billing_phone }` ], [ '_billing_phone', `${ addresses_guest_billing_phone }` ],
[ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], [
'_billing_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_billing_state', `${ addresses_guest_billing_state }` ], [ '_billing_state', `${ addresses_guest_billing_state }` ],
[ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], [
[ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], '_shipping_address_1',
`${ addresses_guest_billing_address_1 }`,
],
[
'_shipping_address_2',
`${ addresses_guest_billing_address_2 }`,
],
[ '_shipping_city', `${ addresses_guest_billing_city }` ], [ '_shipping_city', `${ addresses_guest_billing_city }` ],
[ '_shipping_company', `${ addresses_guest_billing_company }` ], [ '_shipping_company', `${ addresses_guest_billing_company }` ],
[ '_shipping_country', `${ addresses_guest_billing_country }` ], [ '_shipping_country', `${ addresses_guest_billing_country }` ],
@ -551,9 +644,15 @@ export function addOrder( includeTests = {} ) {
'_shipping_first_name', '_shipping_first_name',
`${ addresses_guest_billing_first_name }`, `${ addresses_guest_billing_first_name }`,
], ],
[ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], [
'_shipping_last_name',
`${ addresses_guest_billing_last_name }`,
],
[ '_shipping_phone', `${ addresses_guest_billing_phone }` ], [ '_shipping_phone', `${ addresses_guest_billing_phone }` ],
[ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], [
'_shipping_postcode',
`${ addresses_guest_billing_postcode }`,
],
[ '_shipping_state', `${ addresses_guest_billing_state }` ], [ '_shipping_state', `${ addresses_guest_billing_state }` ],
[ '_payment_method', `${ payment_method }` ], [ '_payment_method', `${ payment_method }` ],
[ '_transaction_id', '' ], [ '_transaction_id', '' ],
@ -564,7 +663,7 @@ export function addOrder( includeTests = {} ) {
[ 'excerpt', '' ], [ 'excerpt', '' ],
[ 'metakeyinput', '' ], [ 'metakeyinput', '' ],
[ 'metavalue', '' ], [ 'metavalue', '' ],
[ 'order_date', `${ order_date }` ], [ 'order_date', `${ global_order_date }` ],
[ 'order_date_hour', '01' ], [ 'order_date_hour', '01' ],
[ 'order_date_minute', '01' ], [ 'order_date_minute', '01' ],
[ 'order_date_second', '01' ], [ 'order_date_second', '01' ],
@ -588,7 +687,7 @@ export function addOrder( includeTests = {} ) {
admin_update_order_id = `${ admin_open_order_base }`; admin_update_order_id = `${ admin_open_order_base }`;
} }
response = http.post( const response = http.post(
`${ base_url }/wp-admin/${ admin_update_order_id }`, `${ base_url }/wp-admin/${ admin_update_order_id }`,
admin_update_order_params.toString(), admin_update_order_params.toString(),
{ {
@ -598,8 +697,8 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Order updated' confirmation": ( response ) => "body contains: 'Order updated' confirmation": ( r ) =>
response.body.includes( `${ admin_update_order_assert }` ), r.body.includes( `${ admin_update_order_assert }` ),
} ); } );
} ); } );
} }
@ -616,8 +715,7 @@ export function addOrder( includeTests = {} ) {
commonNonStandardHeaders commonNonStandardHeaders
); );
const date = new Date(); const order_date = new Date().toJSON().slice( 0, 10 );
const order_date = date.toJSON().slice( 0, 10 );
const orderParams = new URLSearchParams( [ const orderParams = new URLSearchParams( [
[ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ],
@ -747,7 +845,7 @@ export function addOrder( includeTests = {} ) {
admin_update_order_params = orderParams.toString(); admin_update_order_params = orderParams.toString();
} }
response = http.post( const response = http.post(
`${ base_url }/wp-admin/${ admin_update_order }`, `${ base_url }/wp-admin/${ admin_update_order }`,
admin_update_order_params.toString(), admin_update_order_params.toString(),
{ {
@ -757,10 +855,10 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Edit order' header": ( response ) => "body contains: 'Edit order' header": ( r ) =>
response.body.includes( `${ admin_open_order_assert }` ), r.body.includes( `${ admin_open_order_assert }` ),
"body contains: 'Order updated' confirmation": ( response ) => "body contains: 'Order updated' confirmation": ( r ) =>
response.body.includes( `${ admin_created_order_assert }` ), r.body.includes( `${ admin_created_order_assert }` ),
} ); } );
} ); } );
@ -781,7 +879,7 @@ export function addOrder( includeTests = {} ) {
admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`;
} }
response = http.get( const response = http.get(
`${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`,
{ {
headers: requestHeaders, headers: requestHeaders,
@ -790,8 +888,8 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Edit order' header": ( response ) => "body contains: 'Edit order' header": ( r ) =>
response.body.includes( `${ admin_open_order_assert }` ), r.body.includes( `${ admin_open_order_assert }` ),
} ); } );
} ); } );
@ -849,7 +947,7 @@ export function addOrder( includeTests = {} ) {
[ 'metakeyinput', '' ], [ 'metakeyinput', '' ],
[ 'metakeyselect', '%23NONE%23' ], [ 'metakeyselect', '%23NONE%23' ],
[ 'metavalue', '' ], [ 'metavalue', '' ],
[ 'order_date', `${ order_date }` ], [ 'order_date', `${ global_order_date }` ],
[ 'order_date_hour', '01' ], [ 'order_date_hour', '01' ],
[ 'order_date_minute', '01' ], [ 'order_date_minute', '01' ],
[ 'order_date_second', '01' ], [ 'order_date_second', '01' ],
@ -910,7 +1008,7 @@ export function addOrder( includeTests = {} ) {
[ 'excerpt', '' ], [ 'excerpt', '' ],
[ 'metakeyinput', '' ], [ 'metakeyinput', '' ],
[ 'metavalue', '' ], [ 'metavalue', '' ],
[ 'order_date', `${ order_date }` ], [ 'order_date', `${ global_order_date }` ],
[ 'order_date_hour', '01' ], [ 'order_date_hour', '01' ],
[ 'order_date_minute', '01' ], [ 'order_date_minute', '01' ],
[ 'order_date_second', '01' ], [ 'order_date_second', '01' ],
@ -934,7 +1032,7 @@ export function addOrder( includeTests = {} ) {
admin_update_order_id = `${ admin_open_order_base }`; admin_update_order_id = `${ admin_open_order_base }`;
} }
response = http.post( const response = http.post(
`${ base_url }/wp-admin/${ admin_update_order_id }`, `${ base_url }/wp-admin/${ admin_update_order_id }`,
admin_update_order_params.toString(), admin_update_order_params.toString(),
{ {
@ -944,11 +1042,11 @@ export function addOrder( includeTests = {} ) {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Order updated' confirmation": ( response ) => "body contains: 'Order updated' confirmation": ( r ) =>
response.body.includes( `${ admin_update_order_assert }` ), r.body.includes( `${ admin_update_order_assert }` ),
} ); } );
} ); } );
}; }
export default function () { export default function () {
addOrder(); addOrder();

View File

@ -27,7 +27,8 @@ export function homeWCAdmin( includeTests = {} ) {
let response; let response;
let api_x_wp_nonce; let api_x_wp_nonce;
let apiNonceHeader; let apiNonceHeader;
let includedTests = Object.assign( { const includedTests = Object.assign(
{
orders: true, orders: true,
other: true, other: true,
products: true, products: true,
@ -51,8 +52,8 @@ export function homeWCAdmin( includeTests = {} ) {
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: current page is 'Home'": ( response ) => "body contains: current page is 'Home'": ( r ) =>
response.body.includes( 'aria-current="page">Home' ), r.body.includes( 'aria-current="page">Home' ),
} ); } );
// Correlate nonce values for use in subsequent requests. // Correlate nonce values for use in subsequent requests.

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -32,7 +31,6 @@ import {
} from '../../headers.js'; } from '../../headers.js';
export function cartApplyCoupon() { export function cartApplyCoupon() {
let response;
let apply_coupon_nonce; let apply_coupon_nonce;
// let item_name; // let item_name;
let woocommerce_cart_nonce; let woocommerce_cart_nonce;
@ -46,7 +44,7 @@ export function cartApplyCoupon() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=add_to_cart`, `${ base_url }/?wc-ajax=add_to_cart`,
{ {
product_sku: `${ product_sku }`, product_sku: `${ product_sku }`,
@ -74,15 +72,14 @@ export function cartApplyCoupon() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/cart`, { const response = http.get( `${ base_url }/cart`, {
headers: requestheaders, headers: requestheaders,
tags: { name: 'Shopper - View Cart' }, tags: { name: 'Shopper - View Cart' },
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body does not contain: 'your cart is currently empty'": ( "body does not contain: 'your cart is currently empty'": ( r ) =>
response ! r.body.includes( 'Your cart is currently empty.' ),
) => ! response.body.includes( 'Your cart is currently empty.' ),
} ); } );
// Correlate cart item value for use in subsequent requests. // Correlate cart item value for use in subsequent requests.
@ -111,7 +108,7 @@ export function cartApplyCoupon() {
contentTypeRequestHeader contentTypeRequestHeader
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=apply_coupon`, `${ base_url }/?wc-ajax=apply_coupon`,
{ {
coupon_code: `${ coupon_code }`, coupon_code: `${ coupon_code }`,
@ -125,11 +122,11 @@ export function cartApplyCoupon() {
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'Coupon code applied successfully'": ( response ) => "body contains: 'Coupon code applied successfully'": ( r ) =>
response.body.includes( 'Coupon code applied successfully' ), r.body.includes( 'Coupon code applied successfully' ),
} ); } );
response = http.post( const cartResponse = http.post(
`${ base_url }/cart`, `${ base_url }/cart`,
{ {
_wp_http_referer: '%2Fcart', _wp_http_referer: '%2Fcart',
@ -142,10 +139,10 @@ export function cartApplyCoupon() {
tags: { name: 'Shopper - Update Cart' }, tags: { name: 'Shopper - Update Cart' },
} }
); );
check( response, { check( cartResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'woocommerce-remove-coupon' class": ( response ) => "body contains: 'woocommerce-remove-coupon' class": ( r ) =>
response.body.includes( 'class="woocommerce-remove-coupon"' ), r.body.includes( 'class="woocommerce-remove-coupon"' ),
} ); } );
} ); } );

View File

@ -1,5 +1,4 @@
/* eslint-disable no-shadow */ // eslint-disable import/no-unresolved
/* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
*/ */
@ -30,7 +29,6 @@ import {
} from '../../headers.js'; } from '../../headers.js';
export function cartRemoveItem() { export function cartRemoveItem() {
let response;
let item_to_remove; let item_to_remove;
let wpnonce; let wpnonce;
@ -43,7 +41,7 @@ export function cartRemoveItem() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=add_to_cart`, `${ base_url }/?wc-ajax=add_to_cart`,
{ {
product_sku: `${ product_sku }`, product_sku: `${ product_sku }`,
@ -71,15 +69,14 @@ export function cartRemoveItem() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/cart`, { const response = http.get( `${ base_url }/cart`, {
headers: requestheaders, headers: requestheaders,
tags: { name: 'Shopper - View Cart' }, tags: { name: 'Shopper - View Cart' },
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body does not contain: 'your cart is currently empty'": ( "body does not contain: 'your cart is currently empty'": ( r ) =>
response ! r.body.includes( 'Your cart is currently empty.' ),
) => ! response.body.includes( 'Your cart is currently empty.' ),
} ); } );
// Correlate cart item value for use in subsequent requests. // Correlate cart item value for use in subsequent requests.
@ -98,7 +95,7 @@ export function cartRemoveItem() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( const response = http.get(
`${ base_url }/cart?remove_item=${ item_to_remove }&_wpnonce=${ wpnonce }`, `${ base_url }/cart?remove_item=${ item_to_remove }&_wpnonce=${ wpnonce }`,
{ {
headers: requestheaders, headers: requestheaders,
@ -107,8 +104,7 @@ export function cartRemoveItem() {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
"body contains: 'removed'": ( response ) => "body contains: 'removed'": ( r ) => r.body.includes( ' removed.' ),
response.body.includes( ' removed.' ),
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -16,6 +15,8 @@ import {
product_id, product_id,
think_time_min, think_time_min,
think_time_max, think_time_max,
STORE_NAME,
FOOTER_TEXT,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -27,8 +28,6 @@ import {
} from '../../headers.js'; } from '../../headers.js';
export function cart() { export function cart() {
let response;
group( 'Product Page Add to cart', function () { group( 'Product Page Add to cart', function () {
const requestheaders = Object.assign( const requestheaders = Object.assign(
{}, {},
@ -38,7 +37,7 @@ export function cart() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=add_to_cart`, `${ base_url }/?wc-ajax=add_to_cart`,
{ {
product_sku: `${ product_sku }`, product_sku: `${ product_sku }`,
@ -66,26 +65,19 @@ export function cart() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/cart`, { const response = http.get( `${ base_url }/cart`, {
headers: requestheaders, headers: requestheaders,
tags: { name: 'Shopper - View Cart' }, tags: { name: 'Shopper - View Cart' },
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'title is: "Cart WooCommerce Core E2E Test Suite"': ( [ `title is: "Cart ${ STORE_NAME }"` ]: ( r ) =>
response r.html().find( 'head title' ).text() ===
) => `Cart ${ STORE_NAME }`,
response.html().find( 'head title' ).text() === "body does not contain: 'your cart is currently empty'": ( r ) =>
'Cart WooCommerce Core E2E Test Suite', ! r.body.includes( 'Your cart is currently empty.' ),
"body does not contain: 'your cart is currently empty'": ( 'footer contains: Built with WooCommerce': ( r ) =>
response r.html().find( 'body footer' ).text().includes( FOOTER_TEXT ),
) => ! response.body.includes( 'Your cart is currently empty.' ),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -1,9 +1,8 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
*/ */
import { sleep, check, group } from 'k6'; import { sleep, group } from 'k6';
import http from 'k6/http'; import http from 'k6/http';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
@ -15,6 +14,8 @@ import {
think_time_min, think_time_min,
think_time_max, think_time_max,
product_category, product_category,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -22,6 +23,7 @@ import {
commonGetRequestHeaders, commonGetRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function categoryPage() { export function categoryPage() {
let response; let response;
@ -42,23 +44,10 @@ export function categoryPage() {
tags: { name: 'Shopper - Category Page' }, tags: { name: 'Shopper - Category Page' },
} }
); );
check( response, { checkResponse( response, 200, {
'is status 200': ( r ) => r.status === 200, title: `Accessories ${ STORE_NAME }`,
'title is: "Accessories WooCommerce Core E2E Test Suite"': ( body: `<h1 class="woocommerce-products-header__title page-title">${ product_category }</h1>`,
response footer: FOOTER_TEXT,
) =>
response.html().find( 'head title' ).text() ===
'Accessories WooCommerce Core E2E Test Suite',
"body contains: Category's title": ( response ) =>
response.body.includes(
`<h1 class="woocommerce-products-header__title page-title">${ product_category }</h1>`
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -37,6 +36,8 @@ import {
payment_method, payment_method,
think_time_min, think_time_min,
think_time_max, think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -47,9 +48,9 @@ import {
commonPostRequestHeaders, commonPostRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function checkoutCustomerLogin() { export function checkoutCustomerLogin() {
let response;
let woocommerce_process_checkout_nonce_customer; let woocommerce_process_checkout_nonce_customer;
let woocommerce_login_nonce; let woocommerce_login_nonce;
let update_order_review_nonce_guest; let update_order_review_nonce_guest;
@ -64,27 +65,15 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/checkout`, { const response = http.get( `${ base_url }/checkout`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - View Checkout' }, tags: { name: 'Shopper - View Checkout' },
} ); } );
check( response, {
'is status 200': ( r ) => r.status === 200, checkResponse( response, 200, {
'title is: "Checkout WooCommerce Core E2E Test Suite"': ( title: `Checkout ${ STORE_NAME }`,
response body: 'class="checkout woocommerce-checkout"',
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'Checkout WooCommerce Core E2E Test Suite',
'body contains checkout class': ( response ) =>
response.body.includes(
'class="checkout woocommerce-checkout"'
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
// Correlate nonce values for use in subsequent requests. // Correlate nonce values for use in subsequent requests.
@ -107,7 +96,7 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const updateResponse = http.post(
`${ base_url }/?wc-ajax=update_order_review`, `${ base_url }/?wc-ajax=update_order_review`,
{ {
security: `${ update_order_review_nonce_guest }`, security: `${ update_order_review_nonce_guest }`,
@ -131,7 +120,7 @@ export function checkoutCustomerLogin() {
tags: { name: 'Shopper - wc-ajax=update_order_review' }, tags: { name: 'Shopper - wc-ajax=update_order_review' },
} }
); );
check( response, { check( updateResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );
@ -147,7 +136,7 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/checkout`, `${ base_url }/checkout`,
{ {
username: `${ customer_username }`, username: `${ customer_username }`,
@ -186,7 +175,7 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const updateResponse = http.post(
`${ base_url }/?wc-ajax=update_order_review`, `${ base_url }/?wc-ajax=update_order_review`,
{ {
security: `${ update_order_review_nonce_customer }`, security: `${ update_order_review_nonce_customer }`,
@ -210,7 +199,7 @@ export function checkoutCustomerLogin() {
tags: { name: 'Shopper - wc-ajax=update_order_review' }, tags: { name: 'Shopper - wc-ajax=update_order_review' },
} }
); );
check( response, { check( updateResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );
@ -226,7 +215,7 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=checkout`, `${ base_url }/?wc-ajax=checkout`,
{ {
billing_first_name: `${ addresses_customer_billing_first_name }`, billing_first_name: `${ addresses_customer_billing_first_name }`,
@ -252,8 +241,8 @@ export function checkoutCustomerLogin() {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'body contains: order-received': ( response ) => 'body contains: order-received': ( r ) =>
response.body.includes( 'order-received' ), r.body.includes( 'order-received' ),
} ); } );
} ); } );
@ -268,28 +257,14 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/checkout/order-received/`, { const response = http.get( `${ base_url }/checkout/order-received/`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - Order Received' }, tags: { name: 'Shopper - Order Received' },
} ); } );
check( response, { checkResponse( response, 200, {
'title is: "Checkout WooCommerce Core E2E Test Suite"': ( title: `Order received ${ STORE_NAME }`,
response body: 'Thank you. Your order has been received.',
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'Checkout WooCommerce Core E2E Test Suite',
"body contains: 'Thank you. Your order has been received.'": (
response
) =>
response.body.includes(
'Thank you. Your order has been received.'
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
const requestHeadersPost = Object.assign( const requestHeadersPost = Object.assign(
@ -300,14 +275,14 @@ export function checkoutCustomerLogin() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const refreshResponse = http.post(
`${ base_url }/?wc-ajax=get_refreshed_fragments`, `${ base_url }/?wc-ajax=get_refreshed_fragments`,
{ {
headers: requestHeadersPost, headers: requestHeadersPost,
tags: { name: 'Shopper - wc-ajax=get_refreshed_fragments' }, tags: { name: 'Shopper - wc-ajax=get_refreshed_fragments' },
} }
); );
check( response, { check( refreshResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -29,6 +28,8 @@ import {
payment_method, payment_method,
think_time_min, think_time_min,
think_time_max, think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -39,9 +40,9 @@ import {
commonPostRequestHeaders, commonPostRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function checkoutGuest() { export function checkoutGuest() {
let response;
let woocommerce_process_checkout_nonce_guest; let woocommerce_process_checkout_nonce_guest;
let update_order_review_nonce_guest; let update_order_review_nonce_guest;
@ -54,27 +55,14 @@ export function checkoutGuest() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/checkout`, { const response = http.get( `${ base_url }/checkout`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - View Checkout' }, tags: { name: 'Shopper - View Checkout' },
} ); } );
check( response, { checkResponse( response, 200, {
'is status 200': ( r ) => r.status === 200, title: `Checkout ${ STORE_NAME }`,
'title is: "Checkout WooCommerce Core E2E Test Suite"': ( body: 'class="checkout woocommerce-checkout"',
response footer: FOOTER_TEXT,
) =>
response.html().find( 'head title' ).text() ===
'Checkout WooCommerce Core E2E Test Suite',
"body contains: 'woocommerce-checkout' class": ( response ) =>
response.body.includes(
'class="checkout woocommerce-checkout"'
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
// Correlate nonce values for use in subsequent requests. // Correlate nonce values for use in subsequent requests.
@ -97,7 +85,7 @@ export function checkoutGuest() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const updateResponse = http.post(
`${ base_url }/?wc-ajax=update_order_review`, `${ base_url }/?wc-ajax=update_order_review`,
{ {
security: `${ update_order_review_nonce_guest }`, security: `${ update_order_review_nonce_guest }`,
@ -121,7 +109,7 @@ export function checkoutGuest() {
tags: { name: 'Shopper - wc-ajax=update_order_review' }, tags: { name: 'Shopper - wc-ajax=update_order_review' },
} }
); );
check( response, { check( updateResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );
@ -137,7 +125,7 @@ export function checkoutGuest() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const response = http.post(
`${ base_url }/?wc-ajax=checkout`, `${ base_url }/?wc-ajax=checkout`,
{ {
billing_first_name: `${ addresses_guest_billing_first_name }`, billing_first_name: `${ addresses_guest_billing_first_name }`,
@ -163,8 +151,8 @@ export function checkoutGuest() {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'body contains: order-received': ( response ) => 'body contains: order-received': ( r ) =>
response.body.includes( 'order-received' ), r.body.includes( 'order-received' ),
} ); } );
} ); } );
@ -179,28 +167,14 @@ export function checkoutGuest() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/checkout/order-received/`, { const response = http.get( `${ base_url }/checkout/order-received/`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - Order Received' }, tags: { name: 'Shopper - Order Received' },
} ); } );
check( response, { checkResponse( response, 200, {
'title is: "Checkout WooCommerce Core E2E Test Suite"': ( title: `Order received ${ STORE_NAME }`,
response body: 'Thank you. Your order has been received.',
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'Checkout WooCommerce Core E2E Test Suite',
"body contains: 'Thank you. Your order has been received.'": (
response
) =>
response.body.includes(
'Thank you. Your order has been received.'
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
const requestHeadersPost = Object.assign( const requestHeadersPost = Object.assign(
@ -211,14 +185,14 @@ export function checkoutGuest() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.post( const refreshResponse = http.post(
`${ base_url }/?wc-ajax=get_refreshed_fragments`, `${ base_url }/?wc-ajax=get_refreshed_fragments`,
{ {
headers: requestHeadersPost, headers: requestHeadersPost,
tags: { name: 'Shopper - wc-ajax=get_refreshed_fragments' }, tags: { name: 'Shopper - wc-ajax=get_refreshed_fragments' },
} }
); );
check( response, { check( refreshResponse, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -10,7 +9,13 @@ import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { base_url, think_time_min, think_time_max } from '../../config.js'; import {
base_url,
think_time_min,
think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
commonRequestHeaders, commonRequestHeaders,
@ -34,17 +39,13 @@ export function homePage() {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - Site Root' }, tags: { name: 'Shopper - Site Root' },
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'title is: "WooCommerce Core E2E Test Suite"': ( response ) => [ `title is: "${ STORE_NAME }"` ]: ( r ) =>
response.html().find( 'head title' ).text() === r.html().find( 'head title' ).text() === STORE_NAME,
'WooCommerce Core E2E Test Suite', 'footer contains: Built with WooCommerce': ( r ) =>
'footer contains: Built with WooCommerce': ( response ) => r.html().find( 'body footer' ).text().includes( FOOTER_TEXT ),
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -1,9 +1,8 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
*/ */
import { sleep, check, group } from 'k6'; import { sleep, group } from 'k6';
import http from 'k6/http'; import http from 'k6/http';
import { import {
randomIntBetween, randomIntBetween,
@ -13,16 +12,22 @@ import {
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { base_url, think_time_min, think_time_max } from '../../config.js'; import {
base_url,
think_time_min,
think_time_max,
STORE_NAME,
FOOTER_TEXT,
} from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
commonRequestHeaders, commonRequestHeaders,
commonGetRequestHeaders, commonGetRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function myAccountOrders() { export function myAccountOrders() {
let response;
let my_account_order_id; let my_account_order_id;
group( 'My Account', function () { group( 'My Account', function () {
@ -34,27 +39,14 @@ export function myAccountOrders() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/my-account`, { const response = http.get( `${ base_url }/my-account`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - My Account' }, tags: { name: 'Shopper - My Account' },
} ); } );
check( response, { checkResponse( response, 200, {
'is status 200': ( r ) => r.status === 200, title: `My account ${ STORE_NAME }`,
'title is: "My account WooCommerce Core E2E Test Suite"': ( body: 'From your account dashboard you can view',
response footer: FOOTER_TEXT,
) =>
response.html().find( 'head title' ).text() ===
'My account WooCommerce Core E2E Test Suite',
'body contains: my account welcome message': ( response ) =>
response.body.includes(
'From your account dashboard you can view'
),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );
@ -69,26 +61,17 @@ export function myAccountOrders() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( `${ base_url }/my-account/orders/`, { const response = http.get( `${ base_url }/my-account/orders/`, {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - My Account Orders' }, tags: { name: 'Shopper - My Account Orders' },
} ); } );
check( response, {
'is status 200': ( r ) => r.status === 200, checkResponse( response, 200, {
'title is: "My account WooCommerce Core E2E Test Suite"': ( title: `Orders ${ STORE_NAME }`,
response body: '>Orders</h1>',
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'My account WooCommerce Core E2E Test Suite',
"body contains: 'Orders' title": ( response ) =>
response.body.includes( '>Orders</h1>' ),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
my_account_order_id = findBetween( my_account_order_id = findBetween(
response.body, response.body,
'my-account/view-order/', 'my-account/view-order/',
@ -107,28 +90,18 @@ export function myAccountOrders() {
commonNonStandardHeaders commonNonStandardHeaders
); );
response = http.get( const response = http.get(
`${ base_url }/my-account/view-order/${ my_account_order_id }`, `${ base_url }/my-account/view-order/${ my_account_order_id }`,
{ {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - My Account Open Order' }, tags: { name: 'Shopper - My Account Open Order' },
} }
); );
check( response, {
'is status 200': ( r ) => r.status === 200, checkResponse( response, 200, {
'title is: "My account WooCommerce Core E2E Test Suite"': ( title: `My account ${ STORE_NAME }`,
response body: my_account_order_id,
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'My account WooCommerce Core E2E Test Suite',
"body contains: 'Order number' title": ( response ) =>
response.body.includes( `${ my_account_order_id }</h1>` ),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -16,6 +15,8 @@ import {
customer_password, customer_password,
think_time_min, think_time_min,
think_time_max, think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -25,6 +26,7 @@ import {
commonPostRequestHeaders, commonPostRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function myAccount() { export function myAccount() {
let response; let response;
@ -43,21 +45,11 @@ export function myAccount() {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - My Account Login Page' }, tags: { name: 'Shopper - My Account Login Page' },
} ); } );
check( response, {
'is status 200': ( r ) => r.status === 200, checkResponse( response, 200, {
'title is: "My account WooCommerce Core E2E Test Suite"': ( title: `My account ${ STORE_NAME }`,
response body: '>My account</h1>',
) => footer: FOOTER_TEXT,
response.html().find( 'head title' ).text() ===
'My account WooCommerce Core E2E Test Suite',
"body contains: 'My account' title": ( response ) =>
response.body.includes( '>My account</h1>' ),
'footer contains: Built with WooCommerce': ( response ) =>
response
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
// Correlate nonce value for use in subsequent requests. // Correlate nonce value for use in subsequent requests.
@ -95,10 +87,8 @@ export function myAccount() {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'body contains: my account welcome message': ( response ) => 'body contains: my account welcome message': ( r ) =>
response.body.includes( r.body.includes( 'From your account dashboard you can view' ),
'From your account dashboard you can view'
),
} ); } );
const requestHeadersPost = Object.assign( const requestHeadersPost = Object.assign(

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -15,6 +14,8 @@ import {
product_search_term, product_search_term,
think_time_min, think_time_min,
think_time_max, think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -44,25 +45,18 @@ export function searchProduct() {
); );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'title matches: Search Results for {product_search_term} WooCommerce Core E2E Test Suite': [ `title matches: Search Results for {product_search_term} ${ STORE_NAME }` ]:
( response ) => { ( r ) => {
const title_actual = response const title_actual = r.html().find( 'head title' ).text();
.html()
.find( 'head title' )
.text();
const title_expected = new RegExp( const title_expected = new RegExp(
`Search Results for .${ product_search_term }. WooCommerce Core E2E Test Suite` `Search Results for .${ product_search_term }. ${ STORE_NAME }`
); );
return title_actual.match( title_expected ); return title_actual.match( title_expected );
}, },
"body contains: 'Search results' title": ( response ) => "body contains: 'Search results' title": ( r ) =>
response.body.includes( 'Search results:' ), r.body.includes( 'Search results:' ),
'footer contains: Built with WooCommerce': ( response ) => 'footer contains: Built with WooCommerce': ( r ) =>
response r.html().find( 'body footer' ).text().includes( FOOTER_TEXT ),
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -1,22 +1,28 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
*/ */
import { sleep, check, group } from 'k6'; import { sleep, group } from 'k6';
import http from 'k6/http'; import http from 'k6/http';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { base_url, think_time_min, think_time_max } from '../../config.js'; import {
base_url,
think_time_min,
think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
commonRequestHeaders, commonRequestHeaders,
commonGetRequestHeaders, commonGetRequestHeaders,
commonNonStandardHeaders, commonNonStandardHeaders,
} from '../../headers.js'; } from '../../headers.js';
import { checkResponse } from '../../utils.js';
export function shopPage() { export function shopPage() {
let response; let response;
@ -34,22 +40,10 @@ export function shopPage() {
headers: requestHeaders, headers: requestHeaders,
tags: { name: 'Shopper - Shop Page' }, tags: { name: 'Shopper - Shop Page' },
} ); } );
check( response, { checkResponse( response, 200, {
'is status 200': ( r ) => r.status === 200, title: `Shop ${ STORE_NAME }`,
'title equals: Shop WooCommerce Core E2E Test Suite': ( body: '<header class="woocommerce-products-header">',
response footer: FOOTER_TEXT,
) =>
response.html().find( 'head title' ).text() ===
'Shop WooCommerce Core E2E Test Suite',
'body contains: woocommerce-products-header': ( response ) =>
response.body.includes(
'<header class="woocommerce-products-header">'
),
'body contains: woocommerce-loop-product__title': ( response ) =>
response
.html()
.find( '.woocommerce-loop-product__title' )
.toArray().length > 0,
} ); } );
} ); } );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-shadow */
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
/** /**
* External dependencies * External dependencies
@ -16,6 +15,8 @@ import {
product_sku, product_sku,
think_time_min, think_time_min,
think_time_max, think_time_max,
FOOTER_TEXT,
STORE_NAME,
} from '../../config.js'; } from '../../config.js';
import { import {
htmlRequestHeader, htmlRequestHeader,
@ -42,27 +43,18 @@ export function singleProduct() {
} ); } );
check( response, { check( response, {
'is status 200': ( r ) => r.status === 200, 'is status 200': ( r ) => r.status === 200,
'title is: {product_url} WooCommerce Core E2E Test Suite': ( [ `title is: ${ product_url } ${ STORE_NAME }` ]: ( r ) => {
response const title_actual = r.html().find( 'head title' ).text();
) => {
const title_actual = response
.html()
.find( 'head title' )
.text();
const title_expected = new RegExp( const title_expected = new RegExp(
`${ product_url } WooCommerce Core E2E Test Suite`, `${ product_url } ${ STORE_NAME }`,
'i' 'i'
); );
return title_actual.match( title_expected ); return title_actual.match( title_expected );
}, },
'body contains: product SKU': ( response ) => 'body contains: product SKU': ( r ) =>
response.body.includes( `class="sku">${ product_sku }` ), r.body.includes( `class="sku">${ product_sku }` ),
'footer contains: Built with WooCommerce': ( response ) => 'footer contains: Built with WooCommerce': ( r ) =>
response r.html().find( 'body footer' ).text().includes( FOOTER_TEXT ),
.html()
.find( 'body footer' )
.text()
.includes( 'Built with WooCommerce' ),
} ); } );
} ); } );

View File

@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { check } from 'k6';
/**
* Internal dependencies
*/
const checkResponse = (
response,
statusCode,
page = {
title: '',
body: '',
footer: '',
}
) => {
check( response, {
[ `is status ${ statusCode }` ]: ( r ) => r.status === statusCode,
[ `title is: "${ page.title }"` ]: ( r ) =>
r.html().find( 'head title' ).text() === page.title,
[ `body contains: ${ page.body }` ]: ( r ) =>
r.body.includes( page.body ),
[ `footer contains: ${ page.footer }` ]: ( r ) =>
r.html().find( 'body footer' ).text().includes( page.footer ),
} );
};
export { checkResponse };