问题
So I have 2 JSR223 samplers in Jmeter Thread Group.
In the first one, I declare an empty array list
import java.util.List;
import java.util.ArrayList;
myList = new ArrayList();
In the second JSR223 Sampler, that is inside ForEach Controller, I am trying to access myList
variable in order to add some value
import java.util.List;
import java.util.ArrayList;
myList.add(vars.get('trace_id'));
I keep getting the message
Response message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: myList for class: Script468
I was reading this (not official Jmeter docs though) and it says that By default, creating any new variables are local to a thread. It can not be accessed by other threads in the same thread group / other thread groups in the Test plan. so I was thinking I do everything right.
Is it possible to access the variable declared in one groovy sampler (JSR223) in another JSR223 sampler or I am trying to achieve not feasible scenario here?
回答1:
to do that, in first JSR223 Sampler add this:
vars.putObject("myList", myList);
In second one:
def myList = vars.getObject("myList");
See javadocs:
- https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html
来源:https://stackoverflow.com/questions/63637720/jmeter-declare-array-variable-in-one-jsr223-sampler-in-order-to-access-it-in-a