What are the Post Processors in JMeter?

In this article we are going to see what are the post processors of JMeter. For basic idea on Jmeter, see my Previous posts or the Jmeter section under Tool tab.

What is post processor? As we know, jmeter provide request to server and get the request from the server, a post processor can be used to process those data after fetching. You may ask, why. Because, by this action, we can fetch suitable information from the response data. As, post processors process data of response data, so all post processors should be used as child of different type of samplers. Usually it works only with current samples. During execution, post processors run before assertions. So, they can't have assertion results.

There are some technique to use this. We will discuses most of them about that. Let's start with basic introduction with post processors , then let's see how to use individual of them.

How to add post processor? if we right click to a sampler and get the 9 types( with Google plug-ins, 13) of post processors.


So, these are the post processors :

1. BeanShell PostProcessor : Why we use this ?
-To run BeanShell script for getting necessary info from response data.Ex-
-To show save results from response (in file/ command prompt/ etc)
- to get data and process from response

Basic elements are :
Reset bsh.Interpreter before each call : True = Interpreter will be recreated for each sample.
Note : Important for long scripts.
Parameters :
Script file : A file containing the BeanShell script to run. The file name is stored in the script variable FileName
Script : (if no file)The BeanShell script. The return value is ignored.
see this to know how to write scripts.  I will provide a separate post on BeanShell Scripts.

Default BeanShell variables are :
log - (Logger) - Writes to the log file
ctx - ( JMeterContext ) - Gives access to the context
vars - ( JMeterVariables ) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object());
props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
prev - ( SampleResult ) - Gives access to the previous SampleResult
data - (byte [])- Gives access to the current sample data
If the property beanshell.postprocessor.init is set, it will load an initialisation file, defining methods,etc for use in the BeanShell script.

2. BSF PostProcessor: Why we use this ?
 -To extract information PostProcessor allows BSF script code to be applied after taking a sample.

Basic elements are :
Language : The BSF language to be used(one of supported language)
Parameters:  parameters are stored in the variables:
     a. Parameters - string parameters as a single variable
     b. args - String array parameters, split on white-space
Script file: Path of the script file( referenced by "user.dir" System property)
Script: The script to run.

Default variables :
log - (Logger) - Write to log file
Label - String Label
Filename - script file name (if any)
Parameters - parameters (as a String)
args[] - parameters as a String array (split on whitespace)
ctx - ( JMeterContext ) - gives access to the context
vars - ( JMeterVariables ) - gives read/write access to variables: vars.get(key); vars.put(key,val);
vars.putObject("OBJ1",new Object()); vars.getObject("OBJ2");
props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
prev - ( SampleResult ) - gives access to the previous SampleResult (if any)
sampler - (Sampler)- gives access to the current sampler
OUT - System.out - e.g. OUT.println("message")

3. CSS/JQuery Extractor : Why we use this ?
-To extract information from a server response using a CSS/JQuery selector(syntax). Ex-
-To get desirable CSS/JQuery information from response CSS/JQuery
-To get style, data, module

Basic elements are :
Apply to : It will indicate where the extracted information will be used
Main sample only (information useable in main/used sample)
Sub-samples only (information useable in sub-samples)
Main sample and sub-samples - information useable to both.
JMeter Variable - information will be checked with the variable declared here.
Note: This variable should be present previously.

CSS/JQuery extractor Implementation: From 2.9, JSOUP and JODD syntax supported. JSOUP is default.
Reference Name : The variable name that we choose to use the extracted info.
CSS/JQuery expression : HTML purser expression to extract information. See the syntax link for JSOUP and JODD. I will make separate post for this two type of HTML pursers.

Attribute : Name of attribute depend on which syntax we are using. Ex-value. This indicates the value of the css for particulate element.
Match No : Telling which match to use. 0=Random, n=nth match, -n=
used for adding this to ForEach controller
Default Value : If no match, which value will be used.

4. Debug PostProcessor : Why we use this ?
-To create a subSample with the details of the previous Sampler properties, JMeter variables, properties and/or System Properties.
-To use for debugging , effects can be seen with View Result Tree Listener in response data.
Basic elements are :
JMeter Properties : Enables showing JMeter Properties(default False)
JMeter Variables : Enables showing JMeter Variables (default False)
Sampler Properties : Enables showing Sampler Properties(default True)
System Properties : Enables showing System Properties (default False)
 
5. JDBC PostProcessor : Why we use this ?
-To Run a SQL statement just after a sample. Ex-
-To reset state of database that might be changed for testing.
-To validate db changing after testing
Basic elements are :
Variable Name : The variable of jmeter which will get the result of SQL.
SQL Query :
Query Type : Type of Query in combo box

Query : Query as text
Parameter values :  The value will get data from a jmeter variable.
Parameter : Will define what type of parameter inputed from jmeter variable.
variable : Name of the variable that we insert as parameter.
Result variable name : If we assign the result with new jmeter variable.

6. JSR223 PostProcessor: This is same as BSF PostProcessor but allows JSR223 script to run

7. Regular Expression Extractor:  Why we use this ?
-To get our necessary information from response data using Perl regular expression.(work like as Regix) I will make a different post for the regular expression Ex-
- To get header items like token, Session ID, JSON id, cookie id , any spatial variable or information passed.
-To use the founded information for next requests
Basic elements are
Apply to : It will indicate where the extracted information will be used
Main sample only (information useable in main/used sample)
Sub-samples only (information useable in sub-samples
Main sample and sub-samples - information useable to both.
JMeter Variable - information will be checked with the variable declared here.
Note: This variable should be present previously.
Response Field to check :
Body - Check the response body (no headers)
Body (unescaped) - Check the response body(with all Html escape codes replaced
Note : It has performance issues, better to avoid this

Body as a Document - Check various type of documents via Apache Tika (like as View Result Tree's[a listener] doc view).
Headers - Check the headers only( so, should be used with http sample only)
URL : Find in URL
Response Code - Check HTML code. like - 200
Response Message - Check HTML response message like -OK
Reference Name : The variable name that we choose to use the extracted info.
Regular Expression : Perl format expression to extract information(more info will be in separate post)
Template : It indicates which group result will use as string. $2$ means the 2nd group's found string will be used .
 Match No : Indicates which match to use from the group. 0=randome, n(any number) =nth Match, -n=(used for adding this to ForEach controller)
 Default Value : If no match, which value will be used.
Note : Use this for debug(i use my name to find results)

8. Result Status Action Handler : Why we use this ?
- To stop the thread or the whole test if the relevant sampler failed.
Actions are : 
Continue - Continue test by  ignoring error
Start next thread loop - Stop current iteration on error(following the sampler) and restarts the loop to next iteration
Stop Thread - Current thread exits on error
Stop Test - Entire test is stopped at the end of any current samples.
Stop Test Now - The entire test is stopped abruptly(immediately) .
Note: These are same condition like as every type of thread group.

9. XPath Extractor
: Why we use this ?
- To extract info from structured response. Ex-
-to get a table's nth field's value(using query)
-to get attribute's name(using query)

Basic elements are :
Apply to : It will indicate where the extracted information will be used
Main sample only (information useable in main/used sample)
Sub-samples only (information useable in sub-samples
Main sample and sub-samples - information useable to both.
JMeter Variable - information will be checked with the variable declared here.
Note: This variable should be present previously.
Use Tidy (tolerant parser) :
-check this for HTML response, it will be converted to valid XHTML using Tidy
-Un check this for XHTML and XML responses.(like - RSS Feed)
Quiet : Sets the Tidy Quiet flag(enabled with tidy)
Report Errors : If a Tidy error occurs, then set the Assertion accordingly(enabled with tidy)
Show warnings : Sets the Tidy showWarnings option(enabled with tidy) 
Use Namespaces : (if tidy is not selected)
-XML parser will use namespace resolution
Note : Namespaces declared on the root element will be recognized
Validate XML : Check the document against its schema.(if tidy is not selected)
Ignore Whitespace :Ignore Element Whitespace.(if tidy is not selected)
Fetch External DTDs : If selected, external DTDs are fetched(if tidy is not selected)
If "Return entire XPath fragment instead of text content?" is selected, the fragment will be returned rather than the text content.
Reference Name : The variable name that we choose to use the extracted info.
XPath Query : Desire XPath query . I will provide different post for this.
Default Value : If no match, which value will be used.

If we install Jmeter Plugins, we will get those additional. Detail will be given shortly.

1.jp@gc - Inter-Thread Communication PostProcessor
2. jp@gc - XML Format Post Processor
3. jp@gc - JSON Path Extractor
4. jp@gc - JSON Format Post Processor

Highlights :
-Post-Processors are used as a child of a sample
-Post-Processors are run before Assertions

Note : jmeter Plugin install instructions are here 

2 comments:

  1. Thanks for great post. There is another one which describes using Beanshell scripting in JMeter in more details. Check <a href="http://blazemeter.com/blog/queen-jmeters-built-componentshow-use-beanshell'>How to use BeanShell: JMeter's favorite built-in component</a> guide for more details on JMeter API access from within Beanshell script and a kind of Beanshell cookbook.

    ReplyDelete