Wednesday, January 9, 2019

Parsing JSON response and Saving it in CSV

 To parse JSON response we need to use JSON Extractor and Bean Shell Post Process (Here we need some do coding) Add JSON Extractor & Bean Shell post processor to thread group Right click on Thread Group> Add>Post Processor
JSON Extractor & Bean Shell post processor added to thread group 



We are capturing “geoAddressId” and will save it in CSV 





How to Configuring JSON Extractor to Parse JSON Response in JMETER For API  performance Testing


 Variable Name:- You can set any variable name to which Extracted geoAddressId value to be assigned and stored in memory 


JSON Path Expression:-  It allows you to enter search criteria to search Parameter ( you can google Regular Expression for more details ) 

Match No:- 

Default Value- If geoAddressId not found then it will save default value “No geoAddressId found” 


Now we want to save value stored in memory to CSV file, for this we need to write Bean shell Script in Bean shell Post Processor. Open bean shell Post processor. And write below script

import java.io.FileOutputStream; 
import java.util.Map; 
import java.util.Set; 
import java.io.FileWriter; 
String str=vars.get("geoAddressId"); 
FileWriter writer = new FileWriter("D:\\Performance\\Test1\\Test Data sheets\\ADDRESS BS\\geoaddressid.csv",true);  
writer.write(str); 
writer.write("\t"); 
writer.write(System.getProperty("line.separator")); 
writer.close(); 



Now run performance test with 5 users, and check Response as well as geoAddressId stored in CSV 

All 5 users got success


Also in Data sheet all 5 geoAddressId are saved




0 Post a Comment:

Post a Comment