Practical issues and solutions for working with JMeter – Part3

Scenario1:-
How i can extract jmeter response into a variable?
Solution:-
We can achieve it in different ways, we used Json Path PostProcessor
in our example, 
Lets say our response json is in the given format:-

{
"sensorId": "123456bc-25e8-48e1-8abe-b24efe461501",
"sensorName": "waterTemp",
"serialNumber": "4345633352864906",
"status": "ENABLED"
}

Now to extract sensorId based on the “sensorNumber” we can extract it in following manner. 

extract data from json response


Scenario2:-
How we can add response values from jmeter to external file ?
Solution:-
We can achieve it in different ways, we used Bean Sampler
in our example, 
Lets say we want to save the above SENSOR_ID value into external file,

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

Write jmeter results to csv file
Learn More?