0
votes

I have a Jmeter test in which I want to post an XML message to a JMS queue. This message will be formed dynamically via a BeanShell Preprocessor, which pulls data from multiple CSV Data Set Config elements.

One item of this XML message that is dynamic is the number of elements in it - it will be a random number between 1 and 10. For each Line element, I want to pull a different variable from a CSV Data Set Config element. However, I'm finding if I do something like the below, I keep getting the same variable:

for (int i = 0; i < numberOfLines; i++) {
  InputXML = InputXML + "<OrderLine ItemID=\"${ItemID}\" />";
}

The above will keep using the same ${ItemID} variable for all of lines but what I want is for it to grab the next one in the CSV file.

Is there any way to accomplish this via Beanshell?

1

1 Answers

0
votes

To go along with your data, if CSV looks like (first row will saved as variables)

0,1,2,3,4,5,6,7,8,9
a,b,c,d,e,f,g,h,i,j

The Beanshell will use index i to get value of column i in CSV:

String InputXML = "";
for (int i = 0; i < 10; i++) {
    String a = vars.get(String.valueOf(i));
  InputXML = InputXML + "<OrderLine ItemID=\"" + a + "\" />";
}
vars.put("InputXML",InputXML);

InputXML variable will hold the full value.

If you want random value until 10, you can use JMeter function ${__Random(0,10,myRandom)}.

If you want to get random line in CSV you can use the similar answer.