Reputation: 15
i'm trying to save my variables into a csv file by using BeanShell Postprocessor, Code:
String id = "${userID}";
FileWriter fstream = new FileWriter("JmeterBean.csv",true);
fstream.write(id+"\n");
fstream.close();
Test Plan:
HTTP Request GetUsersById => return all IDs
Json extractor => from my response
{"@class":"com.test.dto.userDTO",
"author":"John",
"id":"89BC331D723F", },
{"@class":"com.test.dto.userDTO",
"author":"Alex",
"id":"FTH7JBDRF567",
}
$.[?(@.@class=='com.test.dto.userDTO')].id
-1
BeanShell Postprocessor
But my csv file is always empty and look like that:
Upvotes: 0
Views: 538
Reputation: 1
#The below mentioned solution worked for me:
OrderID = vars.get("primaryRefID");
FileWriter fstream = new
FileWriter("C://Users/Documents/JMeter/OrderID.csv",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("TC-"+OrderID);
out.write(System.getProperty("line.separator"));
out.close();
fstream.close();
Upvotes: 0
Reputation: 168122
If the JSON Extractor produces more than 1 match you don't have the userID
variable, you will have something like:
userID_1=89BC331D723F
userID_2=FTH7JBDRF567
userID_matchNr=2
so I would recommend double checking which JMeter Variables are produced by the JSON Extractor using Debug Sampler and View Results Tree listener combination.
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting
Assuming all above add JSR223 PostProcessor (make sure it's located after the JSON Extractor) and use the following code:
1.upto(vars.get('userID_matchNr') as int, { number ->
new File('JmeterBean.csv') << vars.get('userID_' + number) << System.getProperty('line.separator')
})
Upvotes: 0
Reputation: 15
String id = vars.get("userID");
FileWriter fstream = new FileWriter("JmeterBean.csv",true);
fstream.write(id+"\n");
fstream.close();
I did it but i got the same result with null
in my csv file:
Upvotes: 0