JMeter – Capture Dynamic Value present in Redirected Request

In the correlation article of JMeter, you got detailed knowledge on:

  • What is Correlation?
  • Why correlation is required?
  • How to capture dynamic values?

The purpose of this article is to elaborate on the process of finding out the dynamic value when it is present in the redirected request.

Steps to identify the dynamic value present in the redirected request:

  1. Add a ‘View Results Tree’ listener under the thread group
Figure 01
  1. In the Thread Group, select the ‘Stop Thread’ option for ‘Action to be taken after a sampler error’.
  2. Make sure the input value of the Number of Threads (users), Ramp-up period (seconds), Loop Count should be 1.
Figure 02: Thread Group
  1. Click the ‘Run’ button
  2. The script may fail at a particular sampler where correlation is required.
JMeter - Capture Dynamic Value present in Redirected Request
Figure 03
  1. Check the response code of the main request, if it is 302/Redirect then you need to refer to the ‘View Results Tree’ of the recording log
  2. In this case, the dynamic value appears either in the body or header of the redirected request. 
  3. Generally, these dynamic values fall into the below categories:
    1. Authorization Token
    2. Access Token
    3. CSRF token
    4. Security code
  4. Copy the dynamic value.

Step 1: Refer to the recorded ‘View Results Tree’ listener

Step 2: Paste the copied value in the search field of the recorded View Results Tree listener and press the ‘Search’ button.

Step 3: JMeter will highlight the request where this value is available. Now select the very first highlighted request.

Step 4: Click the ‘Response Data’ tab.

Step 5: Under the ‘Response Data’ tab, click the ‘Response Header’ or ‘Response Body’ tab (wherever dynamic value is present).

Step 6: Again paste the same value in the search field of Response Header/Body and click the ‘Find’ button. Check the place where this dynamic value appeared in the response header/body. The searched value will be highlighted.  

Step 7: You can see the redirected sampler will be disabled in the test plan tree.

JMeter - Capture Dynamic Value present in Redirected Request
Figure 04
  1. In this special case, the request sampler under the thread group is greyed out. This is because the request is re-directed by the previous sampler. JMeter disabled this sampler so that direct request can not be sent while replaying and the previous request should be redirected automatically to this request which is appeared as a child request in the replay ‘View Results Tree’ listener.  
JMeter - Capture Dynamic Value present in Redirected Request
Figure 05
  1. Once JMeter finds out the value then copy the string in such a way that you can write a unique regular expression.
    Learn – How to write the regular expression?
  2. Prepare a regular expression statement which can capture the dynamic value. In this example, the regular expression statement will be:
    access_token=(.*?)& 

Now, the next step is implementation.

Steps to implement the correlation:

  1. For this purpose, add a regular expression extractor under the same sampler whose response contains the dynamic value and paste the regular expression statement (from step 12) in the ‘Regular Expression’ field. Also, provide the Name of the created variable along with the Template, Match No. and Default Value. One point to be noted here is the scope of dynamic value search would be ‘Main sample and sub-samples’ also in some specific cases, verify ‘Field to check’ scope through recorded View Results Tree listener and select the correct option.
Figure 06
  1. The last step is to replace all the occurrences of dynamic values in the subsequent requests by ${<RegExVaribaleName>} syntax. Refer to the below screenshot:
Figure 07
  1. Re-run the script and verify the correctness of correlation by referring to the view results tree listener or by adding a debug sampler.

You may be interested:


Leave a Comment