Using User Defined Variables in JMeter 2.6

JMETER 2.6: 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 better solution. This functionality allows changing parameters in multiple places of test-plan. Let’s see on example, 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 http://jmeter.apache.org to avoid duplicating it in samples (Figure 2).

HTTP Request defaults
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 hardcode it (Figure 3), or move to separate variable.

HTTP Request
Figure 3

Hardcoding is not good if you have hundreds of samplers in test-plan so I decline 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 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 test-plan to see 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 reusable.


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 100,000 concurrent users, real time reporting and nice looking graphs :)
BlazeMeter

provides a performance testing solution that's 100% compatible with Apache JMeter™

Feedback and Knowledge Base