I've created my jMeter test which make 20,000 HTTP requests. I've included the "View Results in Table" listener. After running the test, I would like to save the table results to a CSV file.
8 Answers
The way to do it is using beanshell. You need to download the library and add it to the lib folder. Then create a BeanShell sampler with your request and add code. Something like the following would do:
import org.apache.jmeter.services.FileServer;
// Static elements or calculations
String Variable1 = vars.get("ValueForVariable1AsMentionedInJMeterScript");
String Variable2 = vars.get("ValueForVariable1AsMentionedInJMeterScript");
String Variable3 = vars.get("ValueForVariable1AsMentionedInJMeterScript");
// Open File(s)
f = new FileOutputStream(FileServer.getFileServer().getBaseDir()+"\\NameOfTheCSVFile.csv", true);
p = new PrintStream(f);
// Write data to file
p.println(Variable1 + "," + Variable2 + "," + Variable3);
// Close File(s)
p.close();f.close();
//this is for veryfying your code
return jsonOutput;
ValueForVariable1AsMentionedInJMeterScript is the name of your variable in your script.
For more info please see this page: http://hellotestworld.com/2013/05/02/write-a-file-from-a-jmeter-script/
There are many ways you can push for the results. This is CLI way:
STEPS: 1. download the latest jmeter version
- Extract in your desired directory. For example, extract to
/tmp/
- Now, default output file format will be
csv
. No need to change anything or specify in the CLI command. - Save jmx file from UI console. Say, you have saved on
examples
directory for example: - Now, Run the command from CLI console:
jmeter -n -t examples/test.jmx -l examples/output.csv
Now, if you want to change the default format, check the following parameter in jmeter.properties file: jmeter.save.saveservice.output_format=xml
Now if you run the command, ./jmeter -n -t examples/test.jmx -l examples/output.jtl
output get stored in xml format.
Now, make the request on multiple server(Additional info query for good knowledge): We can specify host and port as argument/tags in CLI command
./jmeter -n -t examples/test.jmx -l examples/output.csv -JHOST=<HOST> -JPORT=<PORT>
You can save the result in any of the listener, below are the steps -
Go to Thread--> Add --> Listener --> View result tree(or any other listener) Picture here
Here you can save the file by giving the file name as abc.csv and go for configure, there you need to uncheck xml file and click on csv file. Also the file result abc.csv is by default saved in the bin folder of the apache-jmeter tool.