The Post-Processors in JMeter are used to perform an action after executing a Samplers request and they run immediately after a Sampler is run. A Post-Processor is usually used to process and extract data from the server’s response.
In our hands on example we will practice the following scenario:
- Create JMeter HTTP Requests to the google.com server
- Get HTML response data from google.com
- Analyze and extract a specific value from the HTML data
Practical Hands On Post-Processor Exercise
For this exercise, you can reuse the Test Plan, which we created in previous article, Sample Test Plan in JMeter. Do not worry if you have not saved the plan, we will recreate it in the steps below.
In previous article, we have seen how we get the HTML code returned from Google in the Response data tab as shown in the screenshot below.
Let us assume that you need to extract the URL associated with the class gb1 highlighted in the screenshot. In a real world project, you can use the below exercise to extract the stock inventory status, pricing details etc from a product details screen of an ecommerce application.
For our example, we need to set up the post-processor so that JMeter can find and extract the value from the pattern <a class=gb1 href=[value_we_need_to_extract]> automatically.
Steps to perform the practical exercise
- Start JMeter. Select the Test Plan, right click on the Test Plan and chose Add > Threads (Users) > Thread Group.
- Set the Thread properties as follow: Number of Thread – 1, Ramp Up Period – 1, Loop Count – 10.
- Select the Thread Group, right click on it and choose Add > Sampler > HTTP Request
- Configure the HTTP Request as follows: Server Name – www.google.com. In the example, we have named the HTTP Request as Google Home Page.
- Now you need to add the CSS/JQuery Extractor Post Processor in JMeter. The CSS/JQuery Extractor helps you to extract the values from a server response using a CSS/JQuery selector syntax.
- To add the extractor, right click on the HTTP Request and choose Add > Post Processors > CSS/JQuery Extractor.
- The next step is to set the extract parameters. In order to configure the CSS/JQuery Extractor first click on it, its configuration panel will display in the right pane. Set its parameters as shown in the screenshot below.
Some of the configuration parameter are explained below:
- Reference Name: The name of the variable. This variable will be used to store the extracted value. In this example our variable name is Title.
- CSS/JQuery expression: a[class=gb1] – We are looking for the string that begin with “a class=gb1” in HTML content
- Attribute: href – We are looking for the value of HTML attribute “href”
- Match No: Set the value to 1. The extractor will return the first match, if there are multiple matches. Setting the value to n where n is any number will return the nth match.
- Default Value: In case a match is not found for the pattern “a class=gb1”, JMeter will set the value of variable Title = NotFound.
- Next we need to add a Debug Sampler. With Debug Sampler, you can see the values of all JMeter variables or properties. Right click on the Thread Group and choose Add > Sampler > Debug Sampler.
- We will use the default setting of Debug Sampler
- Now we can run the Test Plan. Save the Test Plan, then click the Start button in the toolbar.
- Choose one of the Debug Samplers from the results, you will see JMeter extracts the data from the HTML data response from Google.
The above exercise was an example of using JMeter Post-Processor to extract data from response. This topic includes the complete test plan with all the settings mentioned above.
Click here to download the Post-Processor JMeter Test Plan.
In the next topic, you will learn about Controllers in JMeter.