Postman Alternatives for Api Testing
JMeter Post Processors
JMeter Post Processors
Jmeter Processors are utilized to transform the Samplers in their scope. There are two types of processors in Jmeter as Jmeter Post-processors and Jmeter Pre-processors. In this article, we’ll go through post-processors.
- Regular Expression Extractor,
- CSS/jQuery Extractor,
- xPath Extractor,
- Result Status Action Handler,
- BeanShell Post-processor,
- JSR223 Post-processor,
- JDBC Post-processor,
- JSON Extractor,
- Boundary Extractor
Jmeter Post-processors are taking actions after the Sampler is done with its request. You can get the response or gather data into a variable for later use. It is up to your scenario.
Regular Expression Extractor
Regular Expression Extractor is one of the most helpful Jmeter Post-processors in pattern matching. We are using it for the matching pattern on contents, values, and expression. The use of the regular expression is to extract the data from the responses in JMeter. It is also used in capturing dynamic value from the response.
For example, If we want to extract dynamic value from the Google page, the regular expression extractor plays its role from extracting that information from the page.
Refer below steps for Regular Expression Extractor:
- Go to Thread Group
- Add new Sampler
- Right-click on Sampler
- Click on Add
- Click on Post Processors
- Click on Regular Expression Extractor
Now you can find below control-panel with following fields;
Apply to: It defines where you can apply extractor.
The possibilities are
- Main sample and sub-samples
- Main sample only
- Sub-samples only
- JMeter Variable
Field to check: It defines the field of the sampler, which has to be check.
The possibilities are
- Body
- Body (Escaped)
- Body as a Document
- Response Headers
- Request Headers
- URL
- Response Code
- Response message
Reference name: Variable name where results need to be saved.
Regular Expression: It is a sequence of characters that defines the search pattern
Template: It is used to create the string from the found matches.
Match: It identifies which matches we can use for the further process.
Default value: When the regex does not match, in such case variable will be set to the default value.
CSS/jQuery Extractor
CSS/jQuery Extractor is used to extract the values from the response. It uses pre-defined syntax for extracting the element’s value from the web page and then storing same values into created variables. Moreover, this extractor can be used with the request for extracting matching values from the responses.
For example; You can use the commonly-accepted syntax of CSS/jQuery extractor for extracting elements value from any Google web page and then can store that value in a created variable. Now you can use that variable name in next HTTP Request with the Path field for visiting the link which is stored in the created variable.
Here you can find steps:
- Go to Thread Group
- Add new Sampler
- Right-click on Sampler
- Click on Add
- Click on Post Processors
- Click on CSS/jQuery Extractor
Now you are able to find below control-panel of CSS/jQuery Extractor-
Apply To: This can be useful to defines matches need to apply on which sample
The possibilities are
- Main sample and sub-samples
- Main sample only
- Sub-samples only
- JMeter Variable
CSS/jQuery Extractor Implementation: It supports these two: (“JSoup(default)” and “Jodd-Lagarto”) and if the selector is set to empty, the default implementation will be used.
Reference Name: Name of the variable where the result will store.
CSS/jQuery Expression: It is a selector which uses pre-defined syntax for extracting element values.
Attribute: It specifies the attribute of the element that needs to be extracted with the help of a selector.
Match No. (0 for Random): It indicates which match needs to be used.
Default value: Reference variable will be set to the default value if no match found.
XPath Extractor
XPath Extractor comes into play when Regular expression extractor not able to extract the information. To use this XPath Extractor, first of all, you need to add it to the Request sampler. And now can use XPath Tester to extract any value from HTML response and validate same value using XPath extractor.
For Example, You want to validate the title of Google homepage, now extract the value of title from Sampler response using XPath Tester and then store it using Reference name. Now can validate the title using XPath extractor.
Having difficulty with the extraction of information? Don’t worry be happy and follow the below steps:
- Go to Thread Group
- Add new Sampler
- Right-click on Sampler
- Click on Add
- Click on Post Processor
- Click on XPath Extractor
Now you can see below Control-Panel with following fields:
Reference Name: JMeter variable name in which result will be stored.
XPath Query: You can understand it as element query in XPath language and can return more than one match.
Default Value: It returned when no match found. It is also returned when the node has no value and fragment option is not selected.
Result Status Action Handler
Result Status Action Handler allows the user to stop the thread or whole test according to sampler result. Here it defines the action to be taken after a sampler error. You have different choices here, and of course, you can choose from these, action be taken if in any case there is sampler error and this error can happen because of sample failed itself or assertion failed.
For example, you use assertion of 200 response code but because of slow internet connection Google page is not able to load and got other numbers in response code, and you have used “Stop Thread” option, now test will stop here itself with the failed result.
Want to apply constraints for your sampler? Here you go:
- Go to Thread Group
- Add new Sampler
- Right-click on Sampler
- Click on Add
- Click on Post Processors
- Click on Result Status Action Handler
Now you can find below Control-Panel with following choices,
The Possible choices are
Continue: This option ignores the error and continues the test.
Start next thread loop: It does not execute the test for current iteration when it found an error and restarts the loop on next iteration.
Stop Thread: In this option current thread exits.
Stop Test: In this option, the whole test is stopped at the end of any current sample.
Stop Test Now: The entire test is stopped here. Any current samplers are interrupted if possible.
BeanShell PostProcessor
The BeanShell PostProcessor are mainly used in sorting purpose and removing all the unwanted characters like ‘[]’ and ‘,’. This post-processor will act as a filter for you.
Seems interesting? Want to use this filter at your end? Then please follow below path:
- Go to Thread Group
- Add new Sampler
- Right-click on Sampler
- Click on Add
- Click on Post Processors
- Click on BeanShell PostProcessor
Now after adding BeanShell PostProcessor, I will name this PostProcessor as ‘Login Filter’. Here at BeanShell Control-panel, you can see that the script field contains the code that helps in removing the unwanted characters from a string. This string was stored as response data by the Login sampler. Now I will fetch the string from login sampler using the function getResponseDataAsString() of the prev variable. Next, I will use the replace() method of the String class to remove ‘[]’ and ‘,’ characters from the string. Now, will store the filtered string in the “vars” variable and print this final string value.
JSON Extractor
JSON Extractor in Jmeter helps you to use the JSON-PATH syntax to extract data from JSON responses. This post-processor is very much similar to Regular Expression Extractor. You need to use this post-processor with Sampler that has a response. It is one of the very easy ways to extractor from text content. You can extract conditional data and multiple data as well with the help of this extractor.
For Example, you can extractor multiple values from a single document using JSONPath syntax, now suppose you want to extract all cites name from Historical Places web page, and here you can use JSONPath syntax to extract all the values and can store it in the created variable.
Want to try it with your sampler? Then follow me:
- Go to Thread Group
- Add new Sampler
- Right click on Sampler
- Click on Add
- Click on Post Processors
- Click on JSON Extractor
Now, you can see below Control Panel with the following fields;
Apply To: This can be useful to define matches need to apply on which sample.
The possibilities are
- Main sample and sub-samples
- Main sample only
- Sub-samples only
- JMeter Variable
Variable names: Name of the variable where the result will store.
JSON Path expressions: Expressions which were used to extract content from the response.
Match No. (0 for Random): It indicates which match needs to be used.
Compute concatenation var (suffix_ALL): It is used for the concatenation of all extracted values.
Default value: Reference variable will be set to the default value if no match found.
Boundary Extractor
The Boundary extractor allows you to extract values from server response with the help left and right boundaries. Like all other post-processors, this will also execute after Sampler in its scope, it will test the boundaries and then extract the requested values, after this, it will store the value in the given variable name.
For example, you want to extract cites name from Historical Places web page, and you know that city name data surrounded by ‘city:{’ from the left and ‘}’ from the right, so these values need to use in left and right boundaries. And extracted values will store in a created variable.
Here are the steps that will help you with the process of adding Boundary Extractor
- Go to Thread Group
- Add new Sampler
- Right click on Sampler
- Click on Add
- Click on Post Processors
- Click on Boundary Extractor
Here is the control-panel of Boundary Extractor
In the above snap, you are able to find some Parameters. Let me introduce them to you.
Name: It is the name of an element that will display in the tree.
Apply to: It defines match needs to apply on which sample.
Field to Check: It defines the part of the response, which needs to be checked.
Name of the created variable: The name of the variable in which the result is going to store.
Left Boundary: Here you can define the left boundary value for the string.
Right Boundary: Here you can define the right boundary value for the string.
Match No. (0 for Random): It defines which match to use.
Default Value: It defines the value which needs to be set if no match found.
JSR223 Post-processor
JSR223 PostProcessor allows you to apply JSR223 script code after taking a sample. Scripts here have already compiled and it brings significant performance boost. And before invoking the script, some variables are already set so, that it can be used directly. It allows more control over on how extraction took place from the response and how it going to store in variables.
For example, you want to extract value from the response or from User Defined Variable, now you need to use
vars.get(“variable_name”);
//to read or get variable
def var = vars.get(“variable_name”);
//to store value in variable
vars.put(“my_var”, var);
//to display value
Reach out here to use this post-processor:
- Go to Thread Group
- Add new Sampler
- Right click on Sampler
- Click on Add
- Click on Post Processors
- Click on JSR223 PostProcessor
Now, you can see below snap of JSR223 PostProcessor control panel.
JDBC PostProcessor
JDBC Post-processor enables you to run SQL statements just after a sample has run. It can be helpful for you to execute queries against any table for getting the required information and also helpful in case JDBC Sample changes some data during sample run and you want to restore the state.
For example, you want to fetch some data from a table, now select Query Type as “Select Statement” and write SQL Query in Query field. And also enter all variable name in “Variable names” field so that it can return data with respect variable names. You can also enter multiple variable names separated by a comma.
You can find below steps for adding this PostProcessor in your sampler.
- Go to Thread Group
- Add new Sampler
- Right Click on Sampler
- Click on Add
- Click on Post Processors
- Click on JDBC PostProcessor
Now you can fetch the value of below table from database using JDBC post-processor.
Details of JDBC Connection Configuration
Below snap shows you control panel of JDBC PostProcessor:
Hope this article could be helpful for you. If you have a question, simply type below or email me akin [at] loadium [dot] com.
Don’t forget to subscribe newsletter to get articles like this at your inbox.
You can also try our lovely product Loadium.
Stay tuned!