Could anyone help with BeanShell script? So, I'm trying to use a List in my code sample, however, I couldn't define a list properly. The code like this from BeanShell PostProcessor sampler:
import java.io.*;
import java.util.*;
import org.json.*;
import org.apache.jmeter.samplers.SampleResult;
if ((prev.getResponseCode() != null) && (prev.getResponseCode().equals("200") == true)) {
JSONObject response = new JSONObject(prev.getResponseDataAsString());
JSONArray array = response.getJSONArray("users");
List<String> users_list = new ArrayList<String>();
for(int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
users_list.add(object.getString("user_id"));
print(users_list);
}
}
jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``import java.io.*; import java.util.*; import org.json.*; import org.apache.jmete . . . '' Encountered "=" at line 10, column 31.
What Is Beanshell in JMeter? BeanShell is one of the most advanced JMeter built-in components. It supports Java syntax and extends it with scripting features like loose types, commands, and method closures.
Well-behaved JSR223 Sampler with Groovy language and Compilation Cache feature enabled will work faster and have lesser memory footprint than Beanshell. Remember not to reference JMeter Functions or Variables in form of ${var} directly in Groovy script body.
This is the simple way I got to create a list in Jmeter:
Example: creating a list in the size of the number of threads (var parameter):
import java.util.List;
import java.util.ArrayList;
list = new ArrayList();
for(int i = 0; i < ${NumThreads}; i++) {
list.add(i);
}
finally, solved as list = new ArrayList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With