In Apache JMeter, various types of post-processors are available to capture dynamic values such as session IDs, authentication tokens, or transaction IDs. These post-processors are designed to extract and store data from server responses for use in subsequent requests. These post-processors are:
- Regular Expression Extractor or RegEx
- JSON Extractor
- JSON JMESPath Extractor
- Boundary Extractor
- CSS Selector Extractor
However, ensuring these captured values are correct is critical to avoid test failures or unreliable results. This comprehensive guide explains how to verify the captured dynamic values in JMeter, with detailed steps, practical examples, and troubleshooting tips to enhance your test scripts.
Understanding dynamic value extractor in JMeter
Dynamic Value Extractor is a post-processor that extracts specific data from a server response using a pattern. For instance, when testing a web application, you might need to extract a session ID from a login response (e.g., sessionID=123456) to use in subsequent requests. Verifying the captured value ensures it matches the expected format, length, or content, making your test script robust and reliable. Refer to the article for more details.
Why verification for dynamic value in JMeter?
The following are the reasons behind this verification:
- Accuracy: Ensures the extracted value is valid and usable in subsequent requests.
- Debugging: Identifies issues with regex patterns or unexpected server responses.
- Test Reliability: Prevents script failures due to incorrect or missing dynamic data.
- Performance Insights: Validates that the application behaves as expected under load.
Step-by-Step Guide to verify whether the dynamic value is present or not:
Here’s a detailed process to capture and verify a Regex value in JMeter, with practical examples.
- Add a Regular Expression Extractor to the required sampler to capture a dynamic value:
- Right-click on the sampler (e.g., HTTP Request for a login page) in the Test Plan.
- Navigate to Add -> Post Processors -> Regular Expression Extractor
- Configure the following in the Regular Expression Extractor (Refer to Figure 01):
- Reference Name: Name the variable (e.g. sessionID).
- Regular Expression: Write a pattern to match the value. For example, to capture sessionID=123456 from a response, use sessionID=([\d]+).
- Template: Use $1$ to extract the first captured group (e.g., 123456).
- Match No.: Enter 1 for the first match, or 0 for a random match if multiple values exist.
- Default Value: Set a fallback like sessionID_NOT_FOUND to handle cases where the regex fails.
- Validate Using Response Assertion:
- Right-click on the same sampler (e.g., HTTP Request for a login page) in the Test Plan
- Navigate to Add -> Assertions -> Response Assertion
- Configure the following in the Response Assertion (Refer to Figure 02):
- Apply to: Select JMeter Variable and enter the variable name (e.g., sessionID).
- Field to Test: Choose Text Response.
- Pattern Matching Rules: Select ‘Contains’ and check-mark on ‘Not’.
- Patterns to Test: Add the expected pattern (e.g., NOT_FOUND), which indicates that the ‘NOT_FOUND’ regex variable should not have a value containing ‘NOT_FOUND’.
- Run the test:
- If the dynamic value isn’t available, the assertion will fail, and the View Results Tree will show the error.
Example: If the server does not generate a sessionID, the regular expression variable will store the default value, such as sessionID_NOT_FOUND. When this value is checked in the response assertion to ensure it doesn’t contain ‘NOT_FOUND’, the assertion will fail.
- If the dynamic value isn’t available, the assertion will fail, and the View Results Tree will show the error.


Conclusion:
In summary, adding response assertions acts as a safety net to validate the success of dynamic value extraction. It ensures that your test flow remains reliable by catching extraction failures early, helping you maintain the integrity of your performance tests.
You may be interested: