[go: up one dir, main page]

0% found this document useful (0 votes)
178 views22 pages

Pre Processors

This document discusses various preprocessors in JMeter including correlation, parameterization, and synchronization. Correlation extracts dynamic values from responses and uses them in subsequent requests. Parameterization allows executing one test for multiple users by generalizing actions. Synchronization coordinates activities to avoid issues like deadlock. Preprocessors mentioned include Regular Expression Extractor, CSV Data Set Config, BeanShell, BSF, HTML Link Parser, HTTP URL Rewriting Modifier, and others.

Uploaded by

Mayank Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views22 pages

Pre Processors

This document discusses various preprocessors in JMeter including correlation, parameterization, and synchronization. Correlation extracts dynamic values from responses and uses them in subsequent requests. Parameterization allows executing one test for multiple users by generalizing actions. Synchronization coordinates activities to avoid issues like deadlock. Preprocessors mentioned include Regular Expression Extractor, CSV Data Set Config, BeanShell, BSF, HTML Link Parser, HTTP URL Rewriting Modifier, and others.

Uploaded by

Mayank Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

JMeter

Preprocessors

What is it

Pre-processor executes some action before making Sampler Request.

Preprocessors are used to modify the Samplers in their scope.

It Helps to create scenario (Parameterization,Correlation and


Synchronization).

Add a Preprocessor

Create HTTP request

Send to server

Google

Correlation

Correlation is an important aspect in creation of performance testing scripts.


It fetches dynamic values from earlier responses and supplies those values
to subsequent requests.

Its a procedure to fetch a dynamic value from earlier responses and using
that value in subsequent steps

Correlation in JMeter can be achieved using Regular Expression


Extractor,HTTP URL Rewriting etc. post-processor.

Why exactly we need correlation ?


Suppose we have recorded a scenario in which

User enters login details and click OK button


Home page opens and user take further actions
Now, if we just playback this script, the test will fail even for a single user.
This is because of the authentication mechanism used. When we login to a
website, session variables are dynamically created. These session
variables are passed to the subsequent requests and help validation and
authentication of the actions performed. So, one cannot just record and
playback the requests having these variables. Here, we need to correlate
the web requests with the dynamic variables. And for correlation, we need
to use the "Regular Expression Extractor" which makes use of regular
expressions.

Parameterization
Using Parameterization we can execute one test plan for more than one user at the
same time. This is a method of generalizing an action for many users.

Suppose, we have to do load test of a search engine, for that we record the search
scenario. Now to do effective load test, we can't just playback the script for say 100
users. We should simulate 100 users that search for 100 different things. Here we
need parameterization, wherein we can have a CSV file that contains 100 different
items. Now instead of the static search item that we had recorded in our script we can
include the search items from the CSV file dynamically.
We will use 'CSV Data Set Config'. to achieve this in JMeter

Synchronization
Coordinating two or more activities, devices, or processes in time.
We need Synchronization to avoid the condition like deadlock.
We can achieve synchronization by using 'Interthread commincation Preprocessor'
and 'Synchroization Timer'

List

BeanShell
BSF
HTML Link Parser
HTTP URL Rewriting Modifier
Regex user Parameter
User parameter
JDBC
Interthread Communication .
JSR233
Raw Data Source

Beanshell
We wrire arbitary code which execute before sample request we can use it
for parameterization

Process a ramdom number

BSF

We will use javascript to send value to sampler

Test Plan

HTML Link Parser


HTML Link Parser is a preprocessor which parses the HTML
response got to extract data[links, values] and use it dynamically.

Step 1: Create Thread Group under the Test plan .

Step 2: Using proxy setting Record the Form/page[Eg :


SignUp.aspx] which you want to test .

Step 3: Then Add the SignUp.aspx pages[Both Method : Get and


Method :Post ] as child to the Thread Group .

Step 4: Create a CSV file for the fields like User ID , Password ,
e-Mail , Name. Add a CSV Data Config[Config element] to use
the values in Jmeter from the CSV file .

Step 5: Add the SignUp.aspx[Method : GET] Under the Thread Group . So that HTML
Link Parser can fetch the value from the HTTP response .

Step 6: Add the Signup.aspx[Method : POST] as the next HTTP request in the same
Thread Group.

Step 7: Add the HTTP Link Parser as the child of the


HTTP .request[Signup.aspx[Method : POST].

Step 8: Set the Variable in the Send parameter as Request in


theSignUp.aspx[Method : POST] panel accordingly the CSV file we have already
created .

Step 9: Now its time to use the value we parsed using the HTML Link Parser .
Just put [.*] excluding the braces as the Value to the Dropdown field name in the
SignUp.aspx[Method : POST] Panel.

Step 10 : Add a Listener [Preferably View Result in Tree ]. Then Execute/Run the Test
plan .
Consider a simple example: let's say you wanted JMeter to "spider" through website
under test, parse link(check all links on the page) and return the HTML. You would
add some action such as "HTML link parser" to your controller before creating an
HTTP request.

HTTP URL Rewriting Modifier

We can achive correlation

If your web application uses URL rewriting rather than cookies to


save session information, then you'll need to do a bit of extra work to
test your site.

To respond correctly to URL rewriting, JMeter needs to parse the


HTML received from the server and retrieve the unique session ID.
Use the appropriate HTTP URL Re-writing Modifier to accomplish
this Simply enter the name of your session ID parameter into the
modifier, and it will find it and add it to each request

If "Cache Session Id?" is checked, then the last found session id will
be saved, and will be used if the previous HTTP sample does not
contain a session id.

Example
There is a sample
request contains
parameters in url,
what url rewiting do
extract parameter
form url and process
the request as using
session argument
name

Regex user Parameter

Regular Expression Extractor in JMeter is used to fetch values from source


code and use it in subsequent requests. It is one of the most used
components in JMeter as it allows simple ways to handle dynamic requests

Lets create a test plan

Run your script for single user. It may pass or fail.

In View Result Tree listener, go to the response data from where we need to fetch quantity
information. Lets assume the quantity information in response data is <input type=text
name=quantity value=2>. We would be fetching value 2 from this response using regular
expression.

Add Regular Expression Extractor post-processor under this request. We need to now write a
regular expression to fetch quantity value. It can be written as <input type=text name=quantity
value=(.+?)>.

Supply the above expression in Regular Expression field of Regular Expression Extractor postprocessor. Provide other details as well. Template as $1$, Match No. as 1, Default Value as Not
Found, Reference Name as Quantity. Refer this link to know more about all these fields in
Regular Expression Extractor.

Thats it. You can now pass quantity information in subsequent requests using Reference Name
Eg. ${Quantity}.

If you are facing any issue while fetching value, try debugging your regular expression

User Parameter

Allows the user to specify values for User Variables specific to individual threads.
allows you to specify a series of values for any User Variable
Data driven testing with Jmeter user parameters
Based on your requirements, you can select either CSV config element or User
Parameter pre-processor element for data driven testing. If you have large number of
variables to be parameterized, CSV config is the best option.

Example

Add 2 parameters using "user parameter" preprocesser.

Send those paremeter with HTTP login request.

Interthread Communication

Interthread Communication is what where two or more threads are sharing


some information.
There are 4 functions for inter-thread communication in JP@GC: fifoPut,
fifoGet, fifoPop, fifoSize.
fifoPut puts a value into queue and returns stored value. fifoPut parameters:
Name of FIFO queue
String to put into queue
fifoPop gets the string value from FIFO and removes that item from the
queue. If the item not exists, fifoPop will block and wait until some thread
will make fifoPut into queue. There is timeout for such waits, by default it is
unlimited, and can be changed by setting
kg.apc.jmeter.functions.FifoTimeout property into value of seconds. If the
timeout has been exceeded, "INTERRUPTED" value is returned.

fifoGet differs from fifoPop, it does not wait for data, just returns empty string if
no data present in queue. Also it does not remove values from the queue.
fifoSize returns the number of items in the queue.

fifoPop, fifoGet and fifoSize parameters:

Name of FIFO queue


Variable name to store value

You might also like