No results for

Powered byAlgolia

Data uploads with k6 Cloud

suggest edits

Background

Executing tests in k6 Cloud which will upload a data file to the System Under Test (SUT).

Installing k6 locally and authenticating against k6 cloud

In order to upload a file needed for your test to execute you will need to install k6 locally which will act as a CLI between your machine and the k6 Cloud.

For detailed instructions and the different options, read more on running cloud tests from the CLI.

Including a data file in your k6 test script

first option would be to Use the open() scripting API to open a CSV/JSON/TXT file:

more info here: open

users.json
[
{
"username": "user1",
"password": "password1"
},
{
"username": "user2",
"password": "password2"
},
{
"username": "user3",
"password": "password3"
}
]
script.js
1import { sleep } from 'k6';
2const users = JSON.parse(open('./users.json'));
3export default function () {
4 let user = users[__VU - 1];
5 console.log(`${user.username}, ${user.password}`);
6 sleep(3);
7}

another possibility is to Put the data in a JS file and import it as a module:

userData.js
1export let users = [
2 {
3 username: 'user1',
4 password: 'password1',
5 },
6 {
7 username: 'user2',
8 password: 'password2',
9 },
10 {
11 username: 'user3',
12 password: 'password3',
13 },
14];

Main Script:

script.js
1import { sleep } from 'k6';
2import { users } from './userData.js';
3export default function () {
4 let user = users[__VU - 1];
5 console.log(`${user.username}, ${user.password}`);
6 sleep(3);
7}

For more information on data uploads in k6 read data uploads.