如何放置ArrayList< String>对象到jmeter的props变量,并从Beanshell脚本中使用它 [英] How to put an ArrayList<String> object to the props variable of jmeter and use it from Beanshell script

查看:334
本文介绍了如何放置ArrayList< String>对象到jmeter的props变量,并从Beanshell脚本中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从一个beanshell采样器中做到这一点.

I am trying to do this from a beanshell sampler.

import java.util.List;
import java.util.ArrayList;

list = new ArrayList();
props.putObject("list", list );

现在,我想从另一个Beahshell采样器进行此操作.

Now from another Beahshell sampler I want to do this.

list = props.getObject("list");
list.add("Rajan");

然后从第三个Bean Shell采样器

And then from a third Bean shell sampler

log.info("The list is " + list );

如果我们使用vars而不是props,则该代码将起作用.但是vars的作用域仅在单个线程内.我想要测试计划范围内的数组对象. 该代码将引发错误.好像props是一个java.util.Properties类,不能容纳对象.任何想法如何做到这一点.

The code will work if we use vars instead of props. But the scope of vars is inside a single thread only. I want an array object in the scope of the test plan. The code throws an error. seems like props is a java.util.Properties class and cannot hold objects. Any idea how to do this.

在文件中:内联评估:``import java.util.List;导入java.util.ArrayList; //打印报告列表= n. . . "遇到<"在第5行第21列.

In file: inline evaluation of: ``import java.util.List; import java.util.ArrayList; //Prints the report list = n . . . '' Encountered "<" at line 5, column 21.

正如您所说,

推荐答案

props是类型java.util.Properties的对象,该对象是Hashtable的子类.因此,您可以使用putget方法:

props is, as you said, an object of type java.util.Properties, which is a subclass of Hashtable. Therefore you can use put and get methods:

props.put("list", list );

list = props.get("list");

但是, javadoc 这样说强烈建议不要使用它,因为它可能会破坏Properties上的其他操作.因此,使用它需要您自担风险.

However, The javadoc says this is "strongly discouraged" because it could break other operations on Properties. So use it at your own risk.

这篇关于如何放置ArrayList&lt; String&gt;对象到jmeter的props变量,并从Beanshell脚本中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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