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 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:
- Add a ‘View Results Tree’ listener under the thread group
- In the Thread Group, select the ‘Stop Thread’ option for ‘Action to be taken after a sampler error’.
- Make sure the input value of the Number of Threads (users), Ramp-up period (seconds), Loop Count should be 1.
- Click the ‘Run’ button
- The script may fail at a particular sampler where correlation is required.
- Refer to the script and click on the same sampler which is failed during the replay.
- In case there is no value in the Parameters and Body Data tab of the sampler then refer to the request URL in the ‘Path’ field.
- If you identify the value in the URL then copy it.
Step 1: Refer to the recorded ‘View Results Tree’ listener. Paste the copied value in the search field of the recorded View Results Tree listener and press the ‘Search’ button.
Step 2: JMeter will highlight the request where this value is available. Now select the very first highlighted request.
Step 3: Click the ‘Response Data’ tab.
Step 4: Under the ‘Response Data’ tab, click the ‘Response Body’ tab.
Step 5: Again paste the same value in the search field of the 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.
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.
- To verify the correctness of the regular expression statement, write the same regular expression in the search box of the response of the sampler (Recorded View Results Tree Listener).
- Checkmark the ‘Regular exp.’ option.
- Press the ‘Find’ button
OR
- You can also select the ‘RegExp Tester’ from the drop-down of the view results tree listener
- Paste the regular expression statement
- Click ‘Test’.
The result in both cases should highlight the correct dynamic value.
- Repeat these steps until you find all the dynamic values.
Now, the next step is implementation.
Steps to implement the correlation:
- 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 the created variable along with the Template, Match No. and Default Value.
Read about ‘Regular Expression Extractor’ postprocessor
- The last step is to replace all the occurrences of dynamic values in the subsequent requests by ${<RegExVaribaleName>} syntax. Refer to the below screenshot:
- 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: