Jmeter | Passing variables between threads

Goal:

As an automation tester, I would like to pass one variable of one thread group to another thread group. (Sharing variables between threads)

Problem:

JMeter variables have thread scope. This is deliberate, so that threads can act independently. However sometimes there is a need to pass variables between different threads, in the same or different Thread Groups.

Problem Statement

Solution:

One way to do this is to use a property instead. Properties are shared between all JMeter threads, so if one thread sets a property, another thread can read the updated value.

Solution to the Problem Statement
Note: Before executing the test plan do not forget to set check-box “Run Thread Groups consecutively”. It is a must for executing Thread Groups one by one.
  1. Regular Expression Extractor:

Use Regular Expression to extract user_key” & “user_id” and stored in different variables.

2. BeanShell Assertion:

Result of Regular Expression will be stored in variable user_id. And now shuffle on over to BeanShell Assertion.

Explanation of ${__setProperty(user_id,${user_id})}
  • The setProperty function sets the value of a JMeter property.
  • user_id — name of the property that will be set.
  • ${user_id} — is the variable that was stored in Regular Expression Extractor.

3. Get the value of the Property:

Get the value of variables using _property function which returns the value of a JMeter property. ${__property(user_id)}