Roxana
Roxana

Reputation: 33

How to save Jmeter Variables to csv file

Does anyone knoe how to save specific Jmeter Variables into a csv file? I have already tried this topic with no succes: Write extracted data to a file using jmeter and this code:

FileWriter fstream = new FileWriter("result.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(${account_id});
out.close();

Thank you.

Upvotes: 2

Views: 23382

Answers (2)

Meet
Meet

Reputation: 84

You can use this code in your BeanShellPostProcessor. It may help You.

String acid="${account_id}";
FileWriter fstream = new FileWriter("result.csv",true);
fstream.write(acid+"\n");
fstream.close();

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168157

  1. Replace your out.write(${account_id}); stanza with out.write(vars.get("account_id"));
  2. It is better to close fstream instance as well to avoid open handles lack
  3. If you're going to reuse this file, i.e. store > 1 variable, add a separator, i.e. new line

Final code:

FileWriter fstream = new FileWriter("result.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(vars.get("account_id"));
out.write(System.getProperty("line.separator"));
out.close();
fstream.close();

See How to use BeanShell: JMeter's favorite built-in component for comprehensive information on Beanshell scripting

Upvotes: 4

Related Questions