GithubHelp home page GithubHelp logo

isabella232 / k6-example-woocommerce Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grafana/k6-example-woocommerce

0.0 0.0 0.0 41 KB

Example k6 scripts targeting a WooCommerce deployment

JavaScript 100.00%

k6-example-woocommerce's Introduction

k6 eCommerce Demo Scripts

Introduction

This repo contains some example k6 scripts interacting with a basic WooCommerce website hosted at http://ecommerce.test.k6.io.

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.

  1. Install k6 (instructions here)
  2. Clone the repo
  3. Navigate to the directory and k6 run main.js (make sure k6 is on your PATH)

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 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.

k6-example-woocommerce's People

Contributors

tom-miseur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.