I am using JMeter v2.5.
I need to get data from the responses of the test and extract data from it (which I am doing using regular exp extractor). How do I store this extracted data to a file?
Asked
Active
Viewed 7.0k times
20

Kevin
- 53,822
- 15
- 101
- 132

Jigish Chawda
- 2,148
- 1
- 22
- 29
5 Answers
37
Just solved a similar problem. After getting the data using a regular expression extractor, add a BeanShell PostProcessor element. Use the code below to write the variables to a file:
name = vars.get("name");
email = vars.get("email");
log.info(email); // if you want to log something to jmeter.log file
// Pass true if you want to append to existing file
// If you want to overwrite, then don't pass the second argument
f = new FileOutputStream("/my/file/path/result.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
print(name + "," + email);
f.close();

amit_saxena
- 7,450
- 5
- 49
- 64
-
2Also this [link](https://ansonliao.gitbooks.io/jmeter-skill/content/jmeter_how_to_save_variables_to_a_file_after_getting_the_data_using_a_regular_expression_extractor.html) might be helpful. – cuh Sep 12 '18 at 07:11
3
If you just want to write extracted variables to CSV results file, then just add to user.properties the variables you want:
sample_variables=name,email
As per doc:
They will be appended as last column of CSV results file.

UBIK LOAD PACK
- 33,980
- 5
- 71
- 116
2
import org.apache.jmeter.services.FileServer;
String path=FileServer.getFileServer().getBaseDir();
name1= vars.get("user_Name_value");
name2= vars.get("UserId_value");
f = new FileOutputStream("E://csvfile/result.csv", true); //spec-ify true if you want to overwrite file. Keep blank otherwise.
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(name1+"," +name2);
f.close();
this is worked for me i hope it will work for you also

SQA
- 39
- 11
2
You may use https://jmeter-plugins.org/wiki/FlexibleFileWriter/ with sample variables set up. Or with fake Dummy Sampler. Anyway Flexible File Writer is good for writing data into file.

UBIK LOAD PACK
- 33,980
- 5
- 71
- 116

Andrey Pokhilko
- 2,578
- 18
- 19
1
You have a couple options
- You can tally the results by adding an aggregate report listener to your thread group => add listener => aggregate report
- You can get raw results by adding a simple data writer listener to your thread group => add listener => simple data writer
Hope this helps

MatthewJ
- 3,127
- 2
- 27
- 34
-
Actually I need to extact the title and content of the blog in two separate variables and then write them into a certain file in suitable format. – Jigish Chawda Dec 02 '11 at 12:10