Jmeter - declare array variable in one JSR223 Sampler in order to access it in another JSR223 Sampler

断了今生、忘了曾经 提交于 2021-01-28 22:45:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!