Jmeter write out to a file

I have a selenium script which is running in Jmeter using JUnit sampler. My selenium program has a few system.pritnln statements which I see it in console when Jmeter runs, how can I write them to a file?

Answers


I would go for Sample Variables instead so you could get Username included into .jtl results file, add the code like:

  1. In JUnit:

    JUnitSampler sampler = new JUnitSampler();
    JMeterVariables vars = sampler.getThreadContext().getVariables();
    vars.put("username", your_username_variable);
    vars.put("elapsed", your_total_time_variable);
    sampler.getThreadContext().setVariables(vars);
    
  2. In JMeter's user.properties file:

    sample_variables=username,elapsed
    

If you want a separate file - just replace all your System.out.println(""); with:

FileUtils.writeStringToFile(new File("/path/to/file"),"what you need to write", true);

See How to Use JUnit With JMeter article for more information on running your JUnit tests with JMeter


If you do not want to create a separate file and you can use log file then below statement will do to write in a log file

log.info(" TEXT ");

If you want to create a separate file, then

import org.apache.jmeter.services.FileServer;

f = new FileOutputStream("c:/output/result.txt", true); 
p = new PrintStream(f); 
p.println(" Hello World "); // update here what you want to write
p.close();
f.close();

1: Add JSR223 Sampler to yoour test plan

2: Write below code:

FileWriter fstream = new FileWriter("D:\\subid.csv",true); //Create New file with name "subid"

BufferedWriter out = new BufferedWriter(fstream);

out.write(vars.get("variable1"));//write value of variable 1

out.write(",");

out.write(vars.get("variable2"));//write value of variable 2

out.write(System.getProperty("line.separator"));//insert new line

out.close();
fstream.close();

Need Your Help

Problems opening port 80 in w7

windows-7 server port

I am having problems setting up my http server. I have routed my domain to my public ip.

SQLite/MySQL Big Table vs Multiple Small Tables?

mysql sql sqlite minecraft bukkit

I'm developing an Administration plugin for Bukkit Servers. I want to give it the functionality to Ban (normal, temp and ip), Mute (normal and temp), and Warn players. To store all this information...