Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liamseck/k6-wpe-woocommerce
K6 Script Loadtesting a WooCommerce Deployment on WPE
https://github.com/liamseck/k6-wpe-woocommerce
k6 woocommerce wordpress
Last synced: 5 days ago
JSON representation
K6 Script Loadtesting a WooCommerce Deployment on WPE
- Host: GitHub
- URL: https://github.com/liamseck/k6-wpe-woocommerce
- Owner: LiamSeck
- Created: 2024-10-01T10:04:15.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-06T16:51:10.000Z (about 2 months ago)
- Last Synced: 2024-11-06T17:44:16.090Z (about 2 months ago)
- Topics: k6, woocommerce, wordpress
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![k6](https://img.shields.io/badge/k6-7D64FF.svg?style=for-the-badge&logo=k6&logoColor=white)](https://github.com/grafana/k6)![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E.svg?style=for-the-badge&logo=JavaScript&logoColor=black)
# K6 eCommerce Demo Scripts
## Overview
This repo contains some example K6 scripts for interacting with a basic WooCommerce website hosted at https://liamseprod.wpenginepowered.com/.
This repo has been cloned and adapted from from the official K6 WooCommerce example located at https://github.com/grafana/k6-example-woocommerce/
## Introduction
The scripts have been modularized so that each distinct "user action" manifests as its own source file, intended to be used from the entry script, in this case `main.js`. Doing so promotes code reuse and maintainability, as well as catering for some degree of flexibility over the order in which the scripts should run. Obviously, products need to have been added to the cart before checkout can be completed successfully, so there is some sequence that needs to be maintained for them to work as expected.
## Usage
Please note that the server hosting the site is not scaled for heavy loads; the scripts are being provided as working examples. Only run them if you want to see what kind of feedback k6 provides when they are run as part of a test with low numbers of VUs.
1. Install [k6](https://k6.io) (instructions [here](https://k6.io/docs/getting-started/installation/))
2. Clone the repo
3. Navigate to the directory and `k6 run main.js` (make sure k6 is on your PATH)
4. Run `k6 run -e HOSTNAME=domain.com main.js` to change the base URL of the site you are looking to test against (assumes a default WooCommerce installation with default paths)## Contents
The scripts, and their suggested order, are as follows:
`main.js`
The entry script, where k6 `options` would be set, and the script called as part of `k6 run` (see Usage below). Its `export default function` determines what the VUs will run.
`utils.js`
This utility script contains a single exported function `checkStatus` that can be used to verify HTTP status codes. Should the received status code be different from the expected one, a couple of booleans determine whether to print the `Response.body` (if available) and whether to `fail` (skip) the rest of the iteration.
`navigateHomepage.js`
Naturally the first script to be executed. As the homepage also lists the available products on the site, it is also where these are extracted from the response, with a product selected at random and stored in `globalThis.vars["selectedProduct"]`.
`addToCart.js`
Uses (and depends on) the randomly-selected product extracted in `navigateHomepage.js`. An enhancement here might be to make all products available to it (perhaps as input data via the function parameters), such that mutiple products can be added instead of just a single one.
`navigateToCart.js`
The equivalent of the user clicking "View Cart".
`navigateToCheckout.js`
Aside from proceeding to checkout, there are also two dynamic values that need to be extracted from the response and used in the subsequent checkout itself.
`updateAddress.js`
This script represents an AJAX call that takes place when the user enters their address prior to checkout.
`submitCheckout.js`
The final checkout of the cart. A `result: "success"` JSON value is expected in the response, and so a `check` ensures that is the case. The JSON is also expected to contain a `redirectUrl` that takes the user to the confirmation page.