Define a list in BeanShell (jmeter)

Can anyone help with a BeanShell script? So, I'm trying to use List in my sample code, however, I could not correctly define the list. Code like this from the 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. 
+6
source share
2 answers

finally resolved as list = new ArrayList ();

+4
source

This is an easy way to create a list in Jmeter:

Example: creating a list in the amount 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); } 
+3
source

Source: https://habr.com/ru/post/983876/


All Articles