Using User Defined Variables


For example, you have a number of HTTP Requests that have different parameters set but the same URLs. But you know that in future you may want to edit URL. So, what you have to do in such case is to edit EVERY URL. But if you have hundreds of them, it is not good idea.

In this case, User Defined Variables (UDV) will be a better solution. This functionality allows changing parameters in multiple places of the Test-plan. Let’s see an example of how it works.

I’ll create new Test-plan. It will contain one Thread Group and Aggregate Report. Thread group consists of UDV element, HTTP Request Defaults and HTTP Requests (Figure 1).

New test-plan
Figure 1

I specify server name in HTTP Request Defaults as to avoid duplicating it in samples (Figure 2).

HTTP Request defaults
Figure 2

In this Test-plan I want to test . So, I need to specify '/changes.html' as path in HTTP Request. And, there are two ways to do it, I can either hard-code it (Figure 3), or move to separate variable.

HTTP Request
Figure 3

The Hard-code option is not good if you have hundreds of samplers in Test-plan, so I declined such way. I’ll go to 'User Defined Variables' element and fill its fields as specified in Figure 4.

User defined variables
Figure 4

I add a variable PATH that has value '/changes.html'. In “Description” field, I specify for what purpose I’m going to use this variable. After that, I switch to HTTP Request and replace '/changes.html' with expression ${PATH}, where PATH is name of variable that was defined previously. Look at Figure 5

Using variable in HTTP Request
Figure 5

Now, let’s start the Test-plan to see the results.

View results tree
Figure 6

You can see that JMeter replaced ${PATH} with it’s value '/changes.html'. And, If I have to change path, I have only edit PATH values in UDV element. I must say that JMeter 2.6 have some changes in UDV element in comparison with JMeter 2.5.1. So, what are they? See Figure 7.

View results tree
Figure 7
  • Comment field in User Defined Variables is added;
  • User is able to add (paste) entries from the clipboard to an arguments list;
  • User is able to move up or down variables in User Defined Variables;

As you have already noticed, User Defined Variables functionality is very useful if you want to make Test-plans flexible and re-usable.


Want to take your JMeter testing to the next level?

Run your own JMeter scripts in the cloud (JMeter-as-a-service) with up to 1,000,000 concurrent users, real time reporting and nice looking graphs :)
Want to see our testing mobile apps and websites? You'll want to view our on-demand recording, Load Test Like a Pro
Have more questions? Submit a request


  • 0
    Nisarg Patel

    Outstanding Information!! Found interesting and explained in well defined manner. Eager to check other pages also. Please help us like this to Freshers as well as Experienced!! :)

    Have a nice Day!!




    Edited by Nisarg Patel
Please sign in to leave a comment.