Stress Testing Dynamic Pages Using JMeter

Writing a test script for dynamic pages have specific challenges:

  • Links may contain dynamic data.
  • You may have to validate dynamic data in response.

In this article, I will discuss how to create dynamic links in a JMeter script.

Creating a dynamic request path in JMeter has two steps:

  1. Retrieve the dynamic data, such as order ID, from the response of one request. Save the data in a user defined variable.
  2. Use the user defined variable to form the path of a subsequent request.

In our example, we will use order ID as dynamic data.

First, create a user defined variable in the Thread Group (Add > Config Element > User Defined Variable). Initialize the variable with a dummy value that is obviously invalid.


Next, we will need to extract the dynamic data from a response. As a child of the HTTP Request that returns the data, add a Regular Expression Extractor (Add > Post Processor > Regular Expression Extractor).


Assuming that we receive the order ID inside a hidden variable, such as:

<input type=”hidden” name=”orderId” value=”100051″/>

The extractor needs to be configured as follows:

Reference Name: orderId. This is the user defined variable where the extracted data will be saved. Important: It is essential that you define the variable prior to using it in a regular expression extractor. Otherwise, the extractor will create the variable. This will work fine when you run your script from a single thread. But, when you use multiple threads, one thread may overwrite another threads variable. This problem will not occur if you pre-define the variable as we have done here.
Regular Expression: <input type=”hidden” name=”orderId” value=”(.+?)”/>
Template: The position of the value in the regular expression. In our example, there is only one value and we use $1$.
Match No: Number of values in the expression. We have only one.
Default Value: This value will be set to the variable if no match is found. Set it to an obviously invalid value.

Now, all we have to do is use the variable in a HTTP request path to make it dynamic. This is easy. Simply use ${variable} in the path.



3 thoughts on “Stress Testing Dynamic Pages Using JMeter

  1. The above example looks great and very simple. How would you pass the same variable ${orderId} to a BeanShell PostProcesses? I have declared User Defined Variable as shown above, and have tried and tried all possible combinations in the beanshell:

    output = vars.get(“orderId”);
    output = vars.get(${orderId});
    output = vars.get(“${orderId}”);
    and still,; //produces nothing.

    I know that Regular Expression Extractor works, because I am able to print the received expression (4 digits) to a file by calling ${orderId}.

    Thank you so much,

    • Let’s say that you have created a user defined variable called “var1”. Then, you can print it out from a BeanShell PostProcessor as:“Variable: ” + vars.get(“var1”));

      Look at the log output in jmeter.log. You must have at least one HTTP Request element in the test script. Otherwise, Jemeter doesn’t seem to run any of the nodes and you wont see the log output.

  2. Hello and thank you for the reply.

    I have tried the above, and in the log file I see the invalid value for “var1” (blah) that I have created in the user defined variables: Name = var1, Value = blah.

    I do have an HTTP request, but I don’t use any of the UDV in that request. I need to get a result from Response Data window in the View Results Tree, and that response is only 4 digits. I get that result in the Regular Expression Extractor: var1.

    I can print it to a file via Save Responses to a file by using ${var1}, but for some reason I cannot pass it to BeanShell Post Processor.

    it seems to me that the value for UDV var1 never gets a new value from Regular Expression Extractor.

    Perhaps, there is another way of passing values to a script. I don’t need to use just the BS Post Processor. I thought it would be a good way to pass and store the values that I need.

    HELP! please…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s