0
votes

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.

2
Was my answer helpful? You can accpet/upvote. See stackoverflow.com/help/someone-answersuser7294900

2 Answers

2
votes

An answer coming very late; you may already have got your answer. I am still posting my answer so that anyone else, like me, looking for a solution for this requirement, may find it helpful.

When I faced this need, I used the args setting on the JSR223 Assertion script settings.

Since your CSV has many columns, I have used a smaller CSV to demonstrate the solution, one with only 2 columns.

Id,Name
1,New Delhi
2,Calcutta
3,Chennai

enter image description here

Now, access them by index in your Groovy script like this:

println( "Id: " + args[ 0 ] )
println( "Name: " + args[ 1 ] )
0
votes

Don't use ${} syntax inside JSR223 script, it will cache values, use vars.get instead:

 vars.get("Id");