JMeter – User Defined Variables

In JMeter, the User Defined Variables config element is used to declare and define the variables which are used in the JMeter script. Some variables like application URL, port, etc. are generally defined in the User Defined Variable element. 

If you need to define Global variables then add this element under the Test Plan. If it is placed under Thread Group or Sampler then the scope of the variables will be local.

Important Notes: 

  • If User Parameters, Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then JMeter will replace the initial value defined under UDV, and all other test elements in the thread will see the updated value. 
  • In case there is more than one Thread Group then it is advisable to use different names for different values, as UDVs are shared between Thread Groups. 
  • If there is more than one Thread Group then the reference variables can be defined under the Test Plan and made it globally. Because the variables are not available for use until after the element has been processed once.

How to add ‘User Defined Variables’?

You can follow the steps to add User Defined Variable:

  1. Select ‘Test Plan‘ or ‘Thread Group‘ or ‘Sampler’ node
  2. Right-click on the respective node
  3. Hover the mouse on ‘Add’
  4. Hover the mouse on ‘Config Element
  5. Click on ‘User Defined Variables’ 
JMeter - User Defined Variables
Figure 01: User Defined Variables

What are the inputs for ‘User Defined Variables’?

‘User Defined Variables’ element has the following input fields:

  1. Name: To provide element name
  2. Comments: To provide arbitrary comments (if any)
  3. Name: Declare the name of the variable which will be used in the script. 
  4. Value: The value which needs to be passed in the script against that variable. 
  5. Description: This is an optional field to describe the purpose of the variable. 

How to use the variable defined in UDV in the JMeter script?

You can use the variables defined in the UDV in the same way as a regular expression or other runtime element variables are used like ${}. 

Example: If you have a variable named ‘host’ in the User Defined Variables element then it can be used as ${host} in the script.


You may be interested:


Leave a Comment