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);
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 🙂