I though about it when i wanted to execute a data prepration script to generate some system ids and use them in a another script , but how can i get a certain value from the response and write to a file , CSV file specifically.
In this post i will tell you how i did it 🙂
Lets try to make it that way , we will use the random article function in wikipedia website to write the article name to a csv file , so everytime the random article is triggered JMeter will write the new article name to a CSV file.
The following will be added :
- Thread Group
- HTTP Sampler as shown below
- View results tree
- Regular expression extractor as a child to the HTTP Sampler
- BeanShell PostProcessor as a Child to the HTTP Sampler
Every time “https://en.wikipedia.org/wiki/Special:Random” will requested the value in title will be written to the CSV file
Regular Expression Extractor configuration will be as shown below :
One step is remaining , to write the “Article_Name” parameter value to a CSV file
BeanShell PostProcessor code will be as the following :
artname = vars.get("Article_Name");
f = new FileOutputStream("Results.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(artname);
f.close();
Our last step is to run the script with more than one iteration , let’s execute it with 3 iterations and then go to see the CSV fie contents.

Hope you find this article useful 🙂
3 responses to “How to write data from JMeter response to a csv file”
Thanks for sharing the script, works perfect
LikeLiked by 1 person
I tried to do the same. However I am getting null when i print the values to a csv.
LikeLike
Hi kiran , check that your regular expression extractor return actual value , you can check this using “debug sampler”.
Also check your parameter names and make sure that you write them correctly.
Good luck!
LikeLike