I am new to JMeter and trying to perform a load test for the project that I am working on. I have created a test plan to create 2000 users. The resultant request is like below: { : "Status":"200", : "Error":null, : "Content":"1858" } I want to save the value of "Content" for all the 2000 requests in a single csv file. Is there any way to do this?
1 Answers
2
votes
Easy way: append values to .jtl results file
Add the following line to user.properties file (lives under /bin folder of your JMeter installation)
sample_variables=content
Add Regular Expression Extractor as a child of the request which returns that content and configure it as follows:
- Reference Name:
content
- Regular Expression:
"Content":"(\d+)"
- Template:
$1$
When you run JMeter in command-line non-GUI mode as
jmeter -n -t /path/to/your/script.jmx -l /path/to/test/results.jtl
and test execution finishes you will be able to see "Content" values as the last column of results.jtl results file
- Reference Name:
Hard way: custom scripting
- Add a Beanshell PostProcessor as a child of the request which returns that result
Put the following code into the PostProcessor's "Script" area
import java.util.regex.Matcher; import java.util.regex.Pattern; String response = new String(data); FileOutputStream out = new FileOutputStream("content.csv", true); String regex = "\"Content\":\"(\\d+)\""; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(response); if (m.find()) { String content = m.group(1); out.write(content.getBytes()); out.write(System.getProperty("line.separator").getBytes()); out.flush(); }
Once test finishes you will see content.csv file in JMeter's working directory (usually /bin) containing all "Content" values.