Detect and capture dynamic value in redirected requests

The following are steps to find the dynamic value in the rerouted request:

1. Add a listener for “View Results Tree” under the thread group.

2. Choose the ‘Stop Thread’ option under ‘Action to be taken following a sampler error’ in the Thread Group.

3. Make that the input values for Loop Count, Ramp-up period, and Number of Threads (users) are all 1.

4.’Run’ should be selected.

5. The script can stop working at a specific sampling where correlation is needed.

6. Check the response code of the parent’s request; if it’s 302/Redirect, you should see the “View Result Tree” of the recording log

7. In this case, the body or header of the redirected request contains the dynamic value.

8. These dynamic values are generally divided into the following groups:

  • Authorization sheet
  • Access form
  • CSRF tab
  • Security code

9. Copy the dynamic value.

Step 1: View the captured ‘View Result Tree’ listener.

Step 2 – Insert the copied value into the listener search field of the recorded playback result tree, and then click the “Search” button.

In the third step, JMeter marks the request that contains this value. Select the first checked request.

4. Select the “Response Data” tab.

Step 5 – If there is a dynamic value, select the “Comment Header” or “Comment Text” tab on the “Comment Details” page.

Step 6 – Paste the same value again into the response header/body search area and then click the “Search” button. Check the response header/body for the location where this dynamic value appeared. The lookup value is underlined.

Step 7: As you can see in the test plan, the forwarded sample is disabled.

10. The sample of requests within the thread pool is grayed out in this single condition. This is because the previous sampler redirected the request. JMeter disabled this sampler so that direct requests could not be sent on replay and the previous request should be automatically redirected to this request, which appears as a child request in the ‘View Result Tree’ listener of the replay.

11. When JMeter determines the value, copy the string so that you can create a special regular expression.

12. Create a regular expression declaration that can capture the dynamic value. The regular expression declaration for this instance is access_token=(.*?)&

Now comes the time for implementation.

How to implement the correlation:

1. To do this, add a regular expression extractor under the same sample whose response contains the dynamic value and place the regular expression declaration (from step 12) in the ‘Regular Expression’ field. Next to the template, the matching number, and the default value, add the name of the newly formed variable. One thing to note is that the ‘main sample and subsamples’ are the scope of the search for dynamic values. Also, in some specific situations, confirm the scope ‘Field to check’ via the provided View Result Tree listener and choose the correct answer.

2. The final step is to use the syntax $RegExVaribaleName> to replace every instance of dynamic values in subsequent requests. Refer to the image below:

3. Rerun the script to confirm that the correlation is accurate. You can also add a debug sampler or refer to the view results tree listener.

Scroll to Top