How do I pass a variable from one Thread Group to another in JMeter

Viewed 99772

I have a JMeter test with 2 Thread Groups - the first is a single thread (which creates some inventory) and the second has multiple threads (which purchase all the inventory). I use BeanShell Assertions and XPath Extractors to parse the returned value (which is XML) and store variables (such as the ids of the items to be purchased).

But, values that are created in the first Thread Group, whether extracted into standard ${jmeter} type variables, or ${__BeanShell(vars.get("jmeter"))} type vars, are not available in the second Thread Group. Is there anyway to create a variable in the first Thread Group and make it visible to the second?

10 Answers

I was not able to do this with variables (since those are local to individual threads). However, I was able to solve this problem with properties!

Again, my first ThreadGroup does all of the set up, and I need some information from that work to be available to each of the threads in the second ThreadGroup. I have a BeanShell Assertion in the first ThreadGroup with the following:

${__setProperty(storeid, ${storeid})};

The ${storeid} was extracted with an XPath Extractor. The BeanShell Assertion does other stuff, like checking that storeid was returned from the previous call, etc.

Anyway, in the second ThreadGroup, I can use the value of the "storeid" property in Samplers with the following:

${__property(storeid)}

Works like a charm!

JMeter Bean Shell Assertion

Just add a bean shell assertion use a property function to assign the value to a variable (like a global variable) which will hold the value even after it goes to other thread.

thread group >> Add >> Assertions >> Bean Shell Assertion

${__setProperty(Global_variable_Name,${Variable_name_whose_Value_to_be_Passed})}

and then in the other thread you can to call this global variable and can use it

below is the function you need to use to call the stored value:

${__property(global_variable_name)}

https://medium.com/@priyank.it/jmeter-passing-variables-between-threads-a4dc09903b59

This is not possible in JMeter, because it is not normal client behavior (sharing parameters between Threads). Instead of this use one Thread-Group with Controllers:

Thread Group
+ Create inventory
+ + XPath
+ Loop
+ + Purchase inventory

I used set property function and teardown teardowngroup getting values from setupthreadgroup but teardown threadgroup getting 401 error .

I checked all the headers everything look like fine .not sure y teardown failed . Any idea plz advice me

Related