This is documentation for the next version of K6. For the latest stable release, go to the latest version.
utils
Note
The source code for this library can be found in the grafana/k6-jslib-utils GitHub repository.
The utils
module contains number of small utility functions useful in every day load testing.
Simple example
import { sleep } from 'k6';
import http from 'k6/http';
import {
randomIntBetween,
randomString,
randomItem,
uuidv4,
findBetween,
} from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
export default function () {
const res = http.post(`https://quickpizza.grafana.com/api/users`, {
username: `user_${randomString(10)}@example.com`, // random email address,
password: uuidv4(), // random password in form of uuid
});
// find a string between two strings to grab the username:
const username = findBetween(res.body, '"username":"', '"');
console.log('username from response: ' + username);
sleep(randomIntBetween(1, 5)); // sleep between 1 and 5 seconds.
}