How to put an ArrayList<String> object to the props variable of jmeter and use it from Beanshell script

拥有回忆 提交于 2021-01-28 19:14:54

问题


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

Now from another Beahshell sampler I want to do this.

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

And then from a third Bean shell sampler

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

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.

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


回答1:


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

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



来源:https://stackoverflow.com/questions/19243730/how-to-put-an-arrayliststring-object-to-the-props-variable-of-jmeter-and-use-i

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