Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter: How to use ArrayList in Jmeter, Beanshell Sampler?

How to use Array list in Beanshell Sampler-Jmeter?

like image 983
Das Prakash Avatar asked Feb 06 '23 08:02

Das Prakash


1 Answers

Just like in Java, i.e. the following code:

ArrayList myList = new ArrayList();
myList.add("something");
myList.add("something else");

for (int i = 0; i < myList.size(); i++) {
  log.info(myList.get(i));
}

Will print myList contents to jmeter.log file:

Beanshell ArrayList


Remember that Beanshell doesn't support Generics so avoid using diamond operators elsewise you'll get errors. If there is no particular reason for sticking to Beanshell I would suggest considering switching to JSR223 Test Elements and Groovy language - see Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for explanation, benchmarks and scripting best practices.

like image 92
Dmitri T Avatar answered Feb 20 '23 06:02

Dmitri T