k6

A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Documentation

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

open( filePath )

Opens a file, reading all its contents into memory for use in the script. Favourably used to parameterize tests with data from CSV/JSON files etc.

Function only available in "init context"

This is a function that can only be called from the init context (aka "init code"), code in the global context that is, outside of the main export default function { ... }. See example further down on this page. For more in depth description see Running k6.

Parameter
Type
Description

filePath

string

The path to the file, absolute or relative, that will be read into memory. The file will only be loaded once, even when running with several VUs.

Returns:

Type
Description

string

The contents of the file, read as text.

[
  {
    "username": "user1",
    "password": "password1"
  },
  {
    "username": "user2",
    "password": "password2"
  },
  {
    "username": "user3",
    "password": "password3"
  }
]
import { sleep } from "k6";

const users = JSON.parse(open("./users.json"));

export default function() {
  let user = users[__VU - 1];
  console.log(`${user.username}, ${user.password}`);
  sleep(3);
}

open( filePath )