0
votes

Inside the Thread Group, I have "jsr 223 preprocessor" where I am setting variable like this -

List<String> EDPResultList = new ArrayList();
vars.putObject("EDPResultList",EDPResultList);

Then inside the while controller, I have an "HTTP Request Sampler". For processing the response, I have added a "jsr 223 postprocessor" where I am trying to access the object like this -

Object resObj = vars.getObject("EDPResultList");

I am getting the exception -

"ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor For Initial Get javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: EDPResultList for class: Script238 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]"

How can I define a list which I can user throughout my "Thread Group" and for multiple iterations of "While Controller".

2
I think the exception thrown in different code, do you have other code using EDPResultList ? - user7294900

2 Answers

0
votes

To work with ArrayList in JMeter use the following approach:

  1. Test Plan will look like this, first Sampler has JSR223 Pre Processor which initialize the ArrayList. While Controller has second Sampler with JSR223 Post Processor which access the ArrayList. enter image description here
  2. JSR223 Pre Processor inside first Sampler. Put the following code in script area

    import java.util.List;
    
    List<String> list = new ArrayList<>();
    
    list.add("John");
    list.add("Peter");
    list.add("Parkar");
    
    vars.putObject("List",list);
    

    enter image description here

  3. While Controller Condition : ${__BeanShell(${flow}==true,)}. This will run for single loop only, as ${flow} will be set to false in JSR223 Post Processor enter image description here

  4. JSR223 Post Processor inside second Sampler under While Controller. Put the following code in script area. This is how you can access the ArrayList

    ArrayList result = vars.getObject("List");
    for (String value : result) {
    log.info("Values are : " + value);
    }
    vars.put("flow", "false");
    

    enter image description here

  5. Result enter image description here

0
votes

There is nothing wrong with your Groovy code itself:

enter image description here

Most probably your JSR223 Pre Processor is not being executed for some reason, either due to Scoping Rules or missing Sampler as PreProcessors cannot be executed without Samplers. Try adding log.info('something') at the end of the PreProcessor to ensure that it has been run.