I am new to JMeter. I am using 'CSV Data Set Config' with "While Controller". The sample data of CSV file is as follows Example- Id,BobId,TarFulDate,SSRId,EDPNumber,SiteCode,CrBy,CrDate,ModBy,ModDate,Status,Version,ToolVer,ShipDate,TMDate,MaintComments,ParentId,TOName 990:548254,18ATR0002,2018-04-02T10:00:00+05:30,548254,MEATLM-18ATR0002-001,NEATOM,LVerlli,2018-03-01T16:12:37.7230000+05:30,PFibacher,2018-05-15T12:19:33+05:30,Submitted,12,0,1,2018-04-02T10:00:00+05:30,,547011,18ATR0002-0600-0-2
Inside the "While Controller", I have an "If Controller". From Inside the "If Controller" I am sending the "Http Request" using one of the properties "${Id}" of the csv dataset. So far, so good. The HTTP Request correctly takes one row at a time of csv data set and gets the Json response back. Since I have to validate multiple properties of the Json response, I am using "JSR 223 Assertion".
The "JSR 223 Assertion" process the very first of row of CSV Dataset correctly. However, for any subsequent row, it just takes the value of the first row of csv file. So, the assertion of only first row is successful. It fails for rest of the rows. The code is as follows -
import groovy.json.JsonSlurper;
def failureMessage = "";
def jsonResponse = null;
rawId = "${Id}"; //I tried this also. Didn't work.
JsonSlurper JSON = new JsonSlurper ();
try {
jsonResponse = JSON.parseText(prev.getResponseDataAsString());
} catch (Exception e) {
failureMessage += "Invalid JSON.\n"
}
if(!"200".equals(prev.getResponseCode())){
failureMessage += "Expected <response code> [200] but we got [" + prev.getResponseCode() + "]\n\n" ;
}
if ((jsonResponse.createdBy !="${CreatedBy}")) {
failureMessage += "Expected:[" + jsonResponse.createdBy + " Found:" + "${CreatedBy}" + "]\n\n";
}
if ((jsonResponse.id !=rawId)) {
failureMessage += "Expected:[" + jsonResponse.id + " Found:" + rawId + "]\n\n";
}
The expectation is the "JSR 223 Assertion" should access the current data row of the CSV Data Set. As "Http Request" picks the current row correctly inside the same "If Controller" the "JSR223 Assertion" should also do the same.