问题
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