user8463863 user8463863 -3 years ago 138
Java Question

How to store/update a hashmap object in a variable/property in Jmeter

I need to create a hash-map inside of a

JSR233 sampler
that will contain certain headers and properties elements for an external java utility that I will call using a
Java Request Sampler
. I am going to need to create many hashmaps as the key-value pairs will vary based on the systems I am testing. For example, I am going to have to change the
, the
fields for every hash-map. All of this is done inside one thread group, but I may also want to implement it in other thread groups down the road.

How should I structure my Test Plan? Is it possible to create a global variable that will hold the hash-map? And then inside the respective
JSR223 Sampler
, for each test, modify the value of the variable?

I am still fairly new to Jmeter and don't know when to use properties and when to use variables. In this case I would like
var or property that will change throughout my test-plan whenever I create a new hash-map object. I would like to know if this route is feasible, or if an alternative is advised.

The reason I would like to create a HashMap object in Jmeter is because I don't want to have thousands of txt files that the Java utility will read and parse for the key-value pairs (those values vary in every txt file).

Instead I was wondering if there was a way to create this HashMap
object in Jmeter and store it in a variable/property object that can
be passed as a parameter in my
Java Request

Note: I do not want you to create the test plan for me, but rather I would appreciate it if someone with Jmeter experience guide me in the right direction.

Answer Source

You can use special get put operations:

 vars.putObject("map", map);

And get map later:

 map = vars.getObject("map");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download