2

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.

colsw
  • 3,216
  • 1
  • 14
  • 28
Roxana
  • 33
  • 1
  • 1
  • 6
  • Did you try [this](http://stackoverflow.com/questions/15147469/jmeter-not-saving-variables-into-csv-or-xml-files)? – John Oct 03 '14 at 13:32
  • Yes, and the error is : jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``FileWriter fstream = new FileWriter("resultcsv-20141003-163823.csv",true); Buffe . . . '' Encountered "( 2c92c05698458bfcf0c0148d63ba63a21e0" at line 3, column 10. – Roxana Oct 03 '14 at 13:39

2 Answers2

4
  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

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
1

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();
Meet
  • 84
  • 1
  • 6