Friday 6 April 2018

Write Correlated/Extracted Values to a File Using Jmeter

After getting the data using a regular expression extractor/JSON Extractor,
Add a BeanShell PostProcessor element. Use the code below to write the variables to a file:


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