Extract a generated value from script and store in a file

Hi Team,
I have a script where some request Id is getting generated after request is created. Client wants me to extract those values and write into a file. I have extracted the value. can you guide me how to append those into a CSV/ text file.


Hi @namratanirjharini74 For k6 don鈥檛 support write output file using CSV/text. Maybe can done by external library or tools, Maybe use k6 Webpack and ArrayToCSV to save extracted value in array then convert into CSV file.

Hi @namratanirjharini74

Welcome to the community forum :wave:

To add to what @Elibarick mentioned, k6 core does not yet support writing to files. You can follow the issue Provide a file storing API 路 Issue #3017 路 grafana/k6 路 GitHub, and :+1: to help prioritize the implementation.

You鈥檒l also find that using a node module with Webpack might not work. From the docs:

k6 is not NodeJS, nor is it a browser. Packages that rely on APIs provided by NodeJS, for instance, the os and fs modules, will not work in k6. The same goes for browser-specific APIs like the window object.

You can find a good explanation of why fs is not supported on Write data to file - #2 by imiric.

While this is not possible in k6 core, you can use a community extension like GitHub - avitalique/xk6-file: k6 extension for writing files to write to a file. And there are also alternatives to using an extension to send the data to Redis, or a database. If you don鈥檛 necessarily need a local file.

I hope this helps.


1 Like