Imagine a scenario where you have a number of HTTP requests that have different parameters set, but the same URLs. You know that in the future, you may want to edit the URL. In this case, you will have to edit every URL, and if you have hundreds of them, that will be error prone and time intensive.
In this scenario, using User Defined Variables (UDV) is a better approach. This functionality allows changing parameters in multiple places of the test plan. Let’s have a look at an example.
I create a new test plan. It contains one Thread Group and an Aggregate Report. The thread group consists of a UDV element, HTTP Request Defaults, and HTTP Requests (Figure 1).

I specify the server name in HTTP Request Defaults as http://jmeter.apache.org to avoid duplicating it in samples (Figure 2).

In this Test-plan I want to test http://jmeter.apache.org/changes.html . 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.

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.

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

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

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.

- 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?
3 Comments