How to Use the Ultimate Thread Group, the RegEx Extractor and the JSON Path Extractor in Apache JMeter
Apache JMeter™ enables you to create many types of advanced and complex test scenarios. In this blog post we will go over three advanced elements: the Ultimate Thread Group, the RegEx Extractor and the JSON Path Extractor.
The Ultimate Thread Group
JMeter’s Ultimate Thread Group is an element that enables sophisticated management of the thread groups in your load. This is done by enabling you to have an infinite number of rows in the thread schedule, which enables different configurations for different parts of the Thread Group.
First, make sure you installed JMeter plugins.
Right click -> Add-> Threads -> Ultimate Thread Group
Add as many thread counts as you need, and choose the delay, startup time, hold time and shutdown time for each row.
As you can see, this element has a graph at the bottom that visualizes the load. If you change the numbers, the visualization will change as well.
The visualization is a helpful way for seeing the loads we are putting on our system. For example, if we are stress testing the system or if we are accurately simulating our visitors’ usage patterns.
The Regular Expression Extractor
JMeter’s Regular Expression Extractor is an element that lets you extract information from responses. This is useful way for ensuring your pages respond with the information you need them to respond.
1. Add a Thread Group
2. Add a HTTP Request as a Child Element of the Thread Group. In this case, we will test our demo page www.blazedemo.com
3. Add a Regular Expression Extractor - Right Click -> Post Processors -> Regular Expression Extractor
4. We can look for responses in the body, the body unescaped, the body as a document, the response headers, the request headers, the URL, the response code or the response message. In this case we will look at the body.
- Name the Reference, for your convenience
- In the ‘Regular Expression’ field insert the test you’re looking for. In this case, we put in the words ‘Welcome’.
- Template: $0$ - grabs the entire array; $1$ - looks at the first item in the array.
- Match No. (0 for Random): This is important if the response shows up a number of times on the page. 0 - choose a random response; - choose the first response.
- Default Value: The value if the response isn’t found. We recommend you don’t leave this part blank. If you put ‘NOT FOUND’ it’s easier to debug.
5. Add a listener and a Debug Sampler. The Debug Sampler will show the values of the variables from the test run.
We can see that the results came back and that the RegEx came back as “Welcome”.
If the extractor doesn’t find what we want, the result would come back as “Not Found”, like here:
The JSON Path Extractor
JMeter’s JSON Path Extractor is an element for extracting responses from JSON responses. Compared to the RegEx Extractor, it is more resource intensive, so if you can use the RegEx Extractor, we recommend you do so.
1. First, make sure you installed JMeter plugins.
2. Add a Thread Group.
3. Add a Dummy Sampler to your Thread Group - Right Click -> Add-> Sampler -> Dummy Sampler
The Dummy Sampler lets us send any result we want, and is therefore useful for troubleshooting.
4. Insert your JSON payload as the Response Data.
5. Add the JSON Path Extractor - Right Click -> Add -> Post Processors -> JSON Path Extractor
- Choose a Destination Variable Name, for your convenience
- JSONPath Expression: Tell JMeter what to find in the JSON. In this case, any first name among all employees.
- Default Value: Like in the RegEx Extractor, we put in ‘NOT FOUND’.
6. Add a Debug Sampler and a View Results Tree Listener
We can see we got two results back - John and Anna, like we requested.
For more information about the JSON Path Extractor, see here.
BlazeMeter enhances JMeter’s abilities by running JMX tests in the cloud and providing rich reports. Start testing now - just put your URL or JMX file in the box right here and your test will start in minutes. Or, request a BlazeMeter demo.