K6 open function is not loading file content on windows

I am using k6 run to run a test previously built by another person in other computer but seems like open function is not loading the content of json confi file in this javascript test file from k6.

I have readed pages about this but nothing is very clear, what i am doing is this:

  1. i have a file called file1.json
  2. i have other test file (a javascript test file which is calling the file1.json using k6 open function), and this line there: const fileContent = JSON.parse(open(“…/Settings/file1.json”));

The path is right because i can open other files but using import or other javascript methods with the same path.

  1. when i try to use the file content in this javascript test file i see the file content as unknown.

Is this a bug from open method or something else ?

1 Like

hi,

i had the same problem, it turned out for me its a matter of where do you call the open function.

the following is my test script

import http from “k6/http”;

const path = ‘C:\Temp\test.jpeg’;
const imageByte = open(path, “b”);

export default function () {
try {
console.log(“Start”);
console.log(imageByte);
console.log(imageByte.byteLength);
console.log(“Finish”);
} catch (error) {
console.error(error);
return null;
}
}

when i was calling the inside the default function the file wasn’t read and the catch prints the error and “Finish” wasn’t printed on the console, but when i moved the function outside of the default function the error was gone and the bytes length was printed along side with “Finish”
Note: the contents “console.log(imageByte);” will be always empty, i think the CMD doesn’t print the byte array, i was sure that its correct by printing “console.log(imageByte.byteLength);”, it gave me a length which i made sure its correct by writing a C# code that converts an image to a byte array, and the length was the same for the same image

1 Like