I'm trying to make a BeanShell script within JMeter to create an XML message and save it as a variable (and then have a SOAP sampler send the message of course, but that's not really the point). Within the script, I have a loop that randomly creates a few lines, and the point is that every loop the script reads a new line from a CSV file. The loop works fine, but for some reason, the CSVread next
doesn't seem to work so every time it just uses the same line from the CSV file.
Here is the code I'm using:
try{
//Use a random variable to loop for a random amount of times
randomnr = vars.get("randomvariable");
int randomint = Integer.parseInt(randomnr);
int FiNr = 123456789;
//I'm using a stringbuilder to create the xml message
StringBuilder multi = new StringBuilder();
for (int i=1; i<randomint; i++){
multi.append("SomeXML");
FiNr = ${__CSVRead(data.csv,0)}; //get a line from the csv
multi.append(""+FiNr);
multi.append("SomeMoreXML");
${__CSVRead(data.csv,next)}; //Go to the next line in the csv - doesn't seem to be working
}
vars.put("xmlmessage",multi.toString()); //put all of it in a variable
}
catch(Exception ex){
log.warn("Something bad happened", ex);
throw ex;
}
Everything is working except that it's not advancing to the next line within the loop. Any thoughts?
int FiNr = ${__CSVRead(data.csv,0)};
outside of your for loop and${__CSVRead(data.csv,next)};
should beFiNr=${__CSVRead(data.csv,next)};
. – RowlandBFiNr=${__CSVRead(data.csv,next)};
doesn't work because you need to specify the column for the function to return a value. – Ruben van Kruistum