I am using Jmeter as Load Test tool. I passing one parameter through request and in response I am getting only one parameter in result. response. I want to save both request and response in csv file. I am using Regular Expression Extractor to capture response and Bean Shell Postprocessor to save it in csv file. But not able to capture respective request param.
Example: Request : http://localhost:8080/myService?input=abcd123455 and Response : pqrst1245/84985== While here input for request I am taking it from another csv file. and I want to capture both input parameter and corresponding response and store it in csv file like input,response ie. abcd123455,pqrst1245/84985==
Try using this Beanshell... I didn't try it out, but it should work.
import org.apache.jmeter.services.FileServer;
if (sampleEvent.getResult() instanceof org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) {
String request = (sampleEvent.getResult().getSamplerData());
String response = prev.getResponseDataAsString();
fos = new FileOutputStream("/home/user/output.csv", true);
ps = new PrintStream(fos);
StringBuilder sb = new StringBuilder();
sb.append(request).append(",").append(response).append("\n");
ps.println(sb.toString());
ps.close();
fos.close();
}
The easiest way would be using Sample Variables property. Given you have 2 variables ie ${request}
and ${response}
just add the next line to user.properties file:
sample_variables=request,response
and restart JMeter to pick the property up. Once your test will be finished you will see 2 additional columns in the .jtl results file holding ${request}
and ${response}
variable values.
Another way to temporarily set the property is passing it via -J command-line argument like
jmeter -Jsample_variables=request,response -n -t test.jmx -l result.jtl
See Apache JMeter Properties Customization Guide article for more information on working with JMeter properties
I would not recommend to use scripting as when it comes to high load you may experience problems with multiple threads concurrently writing into the same file and you will need to think about implementing some form of write lock
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.