Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write extracted data to a file using jmeter

Tags:

file-io

jmeter

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?

like image 622
Jigish Chawda Avatar asked Dec 02 '11 05:12

Jigish Chawda


4 Answers

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();
like image 55
amit_saxena Avatar answered Nov 05 '22 20:11

amit_saxena


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

like image 33
SQA Avatar answered Nov 05 '22 20:11

SQA


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:

  • https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config

They will be appended as last column of CSV results file.

like image 2
UBIK LOAD PACK Avatar answered Nov 05 '22 20:11

UBIK LOAD PACK


You have a couple options

  1. You can tally the results by adding an aggregate report listener to your thread group => add listener => aggregate report
  2. You can get raw results by adding a simple data writer listener to your thread group => add listener => simple data writer

Hope this helps

like image 1
MatthewJ Avatar answered Nov 05 '22 21:11

MatthewJ