JMeter – Capture Dynamic Value present in Request URL

JMeter - Correlation - Dynamic value in Request URL

In the correlation article of JMeter, you got the 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 request URL. This is a general scenario because most of the time dynamic value is available in the response body and you can easily identify it.

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

  1. Add a ‘View Results Tree’ listener under 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 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 Request URL
Figure 03
  1. Refer to the script and click on the same sampler which is failed during replay.
  2. In case there is no value in the Parameters and Body Data tab of the sampler then refer to the request URL in ‘Path’ field.
  3. If you identify the value in the URL then copy it.
JMeter - Capture Dynamic Value present in Request URL
Figure 04

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

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

Step 3: Click ‘Response Data’ tab.

Step 4: Under ‘Response Data’ tab, click ‘Response Body’ tab.

Step 5: Again paste the same value in the search field of Response Body.

Step 6: Click the ‘Find’ button. Check the place where this dynamic value appeared in the response body. The searched value will be highlighted.  

JMeter - Capture Dynamic Value present in Request URL
Figure 05

Step 7: Once JMeter finds out the value in the response body, then copy the string in such a way so that you can write a unique regular expression.

Learn – How to write the regular expression?

Step 8: Prepare a regular expression statement which can capture the dynamic value. In this example, the regular expression statement will be:

session_code=([0-9a-z-]+)&

Step 9: Verify the correctness of regular expression.

  1. To verify the correctness of regular expression statement, write the same regular expression in the search box of the response of the sampler (Recorded View Results Tree Listener).
  2. Checkmark the ‘Regular exp.’ option.
  3. Press ‘Find’ button

OR

  1. You can also select the ‘RegExp Tester’ from the drop-down of view results tree listener
  2. Paste the regular expression statement
  3. Click ‘Test’.
JMeter - Capture Dynamic Value present in Request URL
Figure 06

The result in both the cases should highlight the correct dynamic value.

  1. Repeat these steps until you find all the dynamic values.

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 8) in the ‘Regular Expression’ field. Also, provide the Name of created variable along with the Template, Match No. and Default Value.

Read about ‘Regular Expression Extractor’ postprocessor

Figure 07
  1. The last step is to replace all the occurrence of dynamic values in the subsequent requests by ${<RegExVaribaleName>} syntax. Refer to the below screenshot:
Figure 08
  1. Re-run the script and verify the correctness of correlation by referring the view results tree listener or by adding a debug sampler.

You may be interested:


Leave a Reply

Your email address will not be published. Required fields are marked *