How to Pass a Variable from One Thread Group to Another in Jmeter

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

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!

How to pass a set of values from one Jmeter Thread group to another

You can save different variables per thread using __threadNum function

 ${__setProperty(categoryID_${__threadNum}, ${categoryID})}

And then get it using same function:

${__property(categoryID_${__threadNum})}

Share Variables Within JMeter Thread Group

  1. You can "stick" each thread (virtual user) to its own ID (or set of IDs from the CSV), i.e. use separate files for each user and __CSVRead() function or single file and __groovy() function to read the values
  2. If you still want to continue with your approach take a look at Inter-Thread Communication Plugin which provides a FIFO queue
  3. Another way is using JMeter Properties if form of name-value pairs of ID=cookie_value, if there is no cookie value for the ID - write the value into the property, if there is - read the value from the property instead of requesting a new cookie

How to pass parameter (token) to another thread group , i need to use the parameter pass from another threadgroup as dynamic url

As per documentation:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

What Regular Expression Extractor gives to you is a JMeter Variable so in order to be able to use it in other thread in this or other thread group you need to convert it into a JMeter Property using __setProperty() function. Once done you can access the value using __P() function

If your logic is more complex, i.e. you need to "wait" in 2nd thread group until the token is available consider using Inter-Thread Communication Plugin

How to use a variable between two thread groups

You can't share a variable, you can convert variable to JMeter property using __setProperty

${__setProperty(propertyName, ${variableName})}

The setProperty function sets the value of a JMeter property.

And use in second thread group use __property

 ${__property(propertyName)}

You can convert it back to JMeter variable:

 ${__property(propertyName, newVariableName)}

${__property(user.dir,UDIR)} - return value of user.dir and save in UDIR



Related Topics



Leave a reply



Submit