i have a small script that reads a file which is
export default function () {
try {
console.log(“Start”);
open(“./testfile.txt”);
console.log(“Finish”);
when i run it, it doesn’t print “Finished” and the “console.error” prints on the console “ERRO[0000] {“value”:{}}”
keep in mind that the script and “testfile.txt” are both in the same location which is the desktop
and k6 version is: k6.exe v0.48.0 (commit/47c0a26798, go1.21.5, windows/amd64)
how can i solve this problem?
It is because open() function is only available in init context.
running the script with e.g. v0.35.0 prints a correct error message:
ERRO[0000] The "open()" function is only available in the init stage (i.e. the global scope), see https://k6.io/docs/using-k6/test-life-cycle for more information source=console
here is the documentation of the open() function
Rewrite the script like this, and it will work fine:
yes, it worked just fine thanks a lot
one question though, how did you get the full error message?
“ERRO[0000] The “open()” function is only available in the init stage (i.e. the global scope), see Test lifecycle for more information source=console”
I tried the examples in the documentation and also with the above script, but still facing the issues.
Here is the exception which I got
getting this error
ERRO[0000] TypeError: Value is not an object: undefined
I tried all the possibilities. Please help me on this.
I am using the K6 version (k6.exe v0.52.0 (commit/20f8febb5b, go1.22.4, windows/amd64))