Jmeter-在一个JSR223采样器中声明数组变量,以便在另一个JSR223采样器中访问它 [英] Jmeter - declare array variable in one JSR223 Sampler in order to access it in another JSR223 Sampler

查看:355
本文介绍了Jmeter-在一个JSR223采样器中声明数组变量,以便在另一个JSR223采样器中访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Jmeter线程组中有2个JSR223采样器.
在第一个中,我声明了一个空数组列表

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();

在第二个JSR223 Sampler(位于ForEach Controller内部)中,我试图访问myList变量以添加一些值

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'));

我一直收到消息

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.

是否可以在另一个JSR223采样器中访问在一个groovy采样器(JSR223)中声明的变量,或者我试图在此处实现不可行的方案?

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?

推荐答案

为此,在第一个JSR223 Sampler中添加以下内容:

to do that, in first JSR223 Sampler add this:

vars.putObject("myList",myList);

vars.putObject("myList", myList);

第二个:

def myList = vars.getObject("mylist");

def myList = vars.getObject("myList");

请参见javadocs:

See javadocs:

这篇关于Jmeter-在一个JSR223采样器中声明数组变量,以便在另一个JSR223采样器中访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆