Home

Awesome

xk6-prompt

Go k6 version xk6 version xk6 version

prompt_example

k6 extension that adds support for input arguments via UI.

Install

  1. Install xk6
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the extension using:
xk6 build --with github.com/Juandavi1/xk6-prompt

Import

import prompt from 'bin/k6/x/prompt';

Input select

export default function () {
  const options = ["smoke", "load"]
  const selected = prompt.select("kind of test", ...options)
  console.log(typeof selected === "string")
}

Read string

export default function () {
  const inputString = prompt.readString("type a string")
  console.log(typeof inputString === "string")
}

Read int

export default function () {
  const inputNumber = prompt.readInt("Type a number")
  console.log(typeof inputNumber === "number")
}

Read float

export default function () {
  const inputNumber = prompt.readFloat("Type a float")
  console.log(typeof inputNumber === "number")
}

Continuous Testing

If you are in a continuous testing environment you can pass the input arguments via environment variables.

Example:

export default function () {
    const myNumber = __ENV.num ? __ENV.num : prompt.readInt("enter a number")
    console.log(typeof myNumber === "number")
}

And run the test with the environment variable:

k6 run -e num=10 script.js

Manually building from source

Install Go tools 1.19

Clone this repo

git clone git@github.com:Juandavi1/xk6-prompt.git

Install dependencies

make install

Build the extension binary

make build

Execute the example using the extension binary

make run

Examples

You can find more examples in the examples folder.

<br/>

#HavingFunLearning 🦾