Hi All,
I am trying to upload data through an excel file to a http request in k6, where in I am using open() given on below link-
Approach 1-
- var filename = csvData[ exec .scenario.iterationInTest] [‘pFileName’]; - Reading unique files sequentially from a CSV file.
const binFile = open (./${filename}
, ‘b’); - Open files(.xls) from csv file.
When I used above 2 functions together in the init context, I am getting below error-
" getting scenario information in the init context is not supported "
Approach 2 - Used open () in default function-
export default function ()
{
let res;
var filename = csvData[ exec .scenario.iterationInTest] [‘pFileName’];
console. log (filename) ;
const binFile = open (./${filename}
, ‘b’);
but getting below error -
“The “Open” function is only available in the init context i.e. global scope”
I have also used-
var filename = csvData[Math. floor (Math. random () * csvData.length)] [‘pFileName’]; - Reading files from CSV randomly.
const binFile = open (./${filename}
, ‘b’);
Getting below error -
‘‘GoError: open() can’t be used with files that weren’t previously opened during initialization (__VU==0),’’
Please help me on this asap.
Thanks!