Practical issues and solutions for working with JMeter – Part3 – User friendly Tech help
Scenario1:-
nHow i can extract jmeter response into a variable?
nSolution:-
nWe can achieve it in different ways, we used Json Path PostProcessor
nin our example,
nLets say our response json is in the given format:-
n
n{ “sensorId”: “123456bc-25e8-48e1-8abe-b24efe461501”, “sensorName”: “waterTemp”, “serialNumber”: “4345633352864906”, “status”: “ENABLED”}n
Now to extract sensorId based on the “sensorNumber” we can extract it in following manner.
nScenario2:-
nHow we can add response values from jmeter to external file ?
nSolution:-
nWe can achieve it in different ways, we used Bean Sampler
nin our example,
nLets say we want to save the above SENSOR_ID value into external file,
n
sensorid= vars.get("SENSOR_ID");
//Adding logs to jmeter
log.info("sensor id is"+sensorid);
// Pass true incase to append file
fileName = new FileOutputStream("/home/path/performance/Tests/result.csv", true);
p = new PrintStream(fileName);
this.interpreter.setOut(p);
print(topic);
fileName.close()
n