JMeter - Tutorial - Venkat - QT
JMeter - Tutorial - Venkat - QT
JMeter - Tutorial - Venkat - QT
JVM – Which is the component in JRE and responsible for execution of Java program, which is
interpreter, which will be responsible to run our java programs line by line.
Performance KPI
Response Time
Latency – Subset of RT, (travelling time etc. i.e. only till the 1 byte of the response
received by the browser/client)
ThroughputQ
1
How many concurrent users can a web server handle? Or Maximum Concurrent VU?
Page
JMeter
JMeter is an open source (performance testing tool) desktop Java application with awesome
testing abilities like “designed to measure the performance of web application” i.e.
Performance testing – Testing a web application against heavy load, multiple & concurrent
user traffic.
o How the “Gmail/Facebook/Yahoo/IRCTC” supporting server will perform when
numbers of users simultaneous access the corresponding accounts – basically have to
do performance testing using performance testing tools like Silk performer, VSTS,
JMeter, Loadrunner etc.
2
Page
Pros of JMeter:-
Cons
Features of JMeter:-
Open Source – JMeter is an open source applicationwhich facilitates users or developers to use
source code for other development.
User Friendly GUI – Extremely easy to use & doesn’t take time to get familiar with it
Platform Independent – It’s 100% pure java desktop application. So it can run on any platforms.
It is highly extensible and capable to load the performance test using many protocols.
Highly Extensible- JMeter is designed based on plugins. So most of its “out of the box” features
are applied with plugins. Using plugins we can write our own test case to extend the testing
process. JMeter uses text editor to create a test plan and supplies in XML format.
Support various testing approach or strategies – JMeter supports various testing approach
such as Load Testing, Stress Testing, Distributed Testing and Functional Testing etc.
Script Test - JMeter is capable to perform automation testing using “Bean Shell & Selenium”.
(Integrated with Bean Shell & Selenium)
Simulation - JMeter can simulate various users with simultaneous threads, generate heavy load
against web application under test.
4
Page
Visualize Test Result - Test result can be display in a different format such as chart, table, tree
and log file
Easy installation – Just copy and run the *.bat file to run JMeter.
Support multi-protocol: JMeter does not only support web application testing, but also evaluate
database server performance. Below are list of protocolsthat are supported by JMeter
Record & Playback - Record the user activity on the browser and simulate them in web
application using JMeter
Email Support –JMeter has extensive Email capabilities, so JMeter send emails based on the test
results.
5
Page
JMeter simulates a group of users sending requests to target server and return statistics
information that shows the performance/functionality of target server/application via
tables, graphs, summary table etc. Based on the above we will analyze the test results
and prepare the reports.
6
Page
Installation of JMeter:-
Before installation we need to check the system is supporting Java or Not if not install
Java. Use the below command to check Java is installed or not on the system
In Windows/Linux, open the Terminal and type the command “java –version”
o If Java run time is installed successfully then below is the corresponding output.
o If java run time is not installed the below is the corresponding output
If OS is Mac, the command to find the java version is “machine: ~ joseph$ java –version”
Pre-requisite - Should have latest version of Java Development Kit.I.e. JVM o JKD 6 or
higher.
The SW is available at
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-
1880260.htmlor
http://www.java.com/en/download/windows_xpi.jsp
Download the required JDK and install it. After installation use “java –version” command
to check Java runtime environment is installed or not.
7
Page
Go to control panel and check Java is available or not and also the version (Programs &
features).
8
Page
GUI Mode
Server Mode
Command Line Mode
i) GUI Mode – JMeter runs on client computer. Just click on the file “apache-jmeter-
2.13\bin\jmeter.bat”
9
Page
After clicking on the “jmeter.bat” file then it will launch or open the JMeter which is shown below.
JMeter are called Listeners i.e. Report = Listener (View results in table, Graph results…)
In order to run the test need to save the test (Click Save)
Page
Java Compiler – Allows developers to build JMeter source code & other JMeter plugins
SAX XML Parser – It is simple API for XML, we can use SAX XML parser as an
alternative to XML parse in JMeter
Email Support available in JMeter using POP3/IMAP sampler.
JDBC Driver – Can test the DB server.
Test Plan:-
It is top level body of JMeter, which explains the sequence of steps to execute at run time.
A final test plan has “one or more Thread groups, Sampler, Logic Controllers, Listeners,
12
13
Page
Parameters:-
Name: Specify the Name for the test plan. Ex: USA Bank etc.
Comments: Provide any comments if necessary
User Defined Variables – We can define any variable that will be used in the JMeter scripts.
If we check Run Thread Groups consecutively (i.e. run groups one at a time) – Then JMeter
will run the Thread Groups in the Order they have defined. Ex: I have 2 thread groups in my
test case. Group A should complete first before Group B starts to execute.
Run teardown Thread Groups after shutdown of main threads–If we check this option
then the “teardown” thread group will execute after shutdown of the mail thread or main load
test.
Functional Test Mode – If we check this option then JMeter will store the data for the page
requested (response, user input data or sample data) in a log file. This will be used when you
want to use JMeter as a functional testing tool.
Work Bench:-
The workbench provides a place to store test elements temporarily. Not bonding with the
Test Plan.
JMeter will not save the content of Work Bench, It will save only the contents of Test Plan.
Here we need to remember 3 important things before recording the script with JMeter.
o JMeter will record the browser action using a proxy server, so we need to configure
our browser to use the JMeter proxy.
o JMeter needs port to record browser actions, so need to provide the port number that
is not in use in our Test Controller in the port section as shown in the above diagram.
o If the port number mentioned in the port section EX: 8888 is free then we will not get
any error after click on the start button
o If the port number mentioned in the port section is already using by other applications
then we will get the below error after clicking on the start button.
o So we need to identify the port number that is not in use by using “netstat –a”
command in the command line and enter the port number that is not in use. (Should
15
not use the state of the port as “LISTENING”, “ESTABLISHED”) in the netstat –a results.
Page
16
Page
17
Page
o Click on OK button.
o Now click on “Start” button in JMeter proxy server i.e. in the HTTP(S) Test Script
Recorder and launch the Firefox browser and execute the steps for the Performance
Scenario.
Threads (Users):-
Thread Group:-
It is an initial stage of test plan. It represents group of Threads i.e. group of Users.
Each thread represents one virtual user using the application under test. (i.e. each user
simulates one real user request to the server)
The controls for a thread group allow you to set number of threads for each group. i.e. if the
controls value is 100 then JMeter will creates & simulate 100 users request to the server. And
also we can control Ramp Up and the number of test iterations.
Parameters:-
Action to be taken after a sampler error
o Continue – If we selected this option then the test will continue even after getting an
error for a request
o Start Next Thread Loop –If we select this option, and if we get an error for any request
then JMeter will stop the current loop and start the next loop for the same thread.
o Stop Thread –Kill the current thread only
o Stop Test –if Sample error occur then all threads stops its execution at the end of the
current samples.
o Stop Test Now - if Sample error occur then all threads stops abruptly
Number of Threads – Which describes the total number of threads or users used to execute
19
the Test Plan i.e. load test. Each and every user will execute the test plan completely based on
Page
the conditions.
Ramp-Up Period (Sec) – The time to load all users given in. For EX: 100 threads and Ramp-
Up Period is 100 sec then JMeter will load all 100 users in 100 sec i.e. for every 1 sec the user
will be loaded.
Loop Count – Which describes how many time the test plan should be executed.
o If we set 5 in the Loop count then JMeter will execute entire test plan for 5 times
o If we select option Foreverthen the test plan will run for forever, we have stop it
manually to stop the load test.
Delay Thread creation until needed -
Scheduler –Using this we can specify the stat time (when to start the load test), end time
(when to End the load test), duration (how much time the test to be executed) and start up
delay (using this option we can delay the starting of the load test) of the load test.
Test Fragment:-
21
It is a special type of element placed at the same level as Thread Group element.
Page
It gets executed only when it is referenced by a Module or include controller from other
thread groups.
It acts like a library of reusable of scripts. This element is purely for code re-use within Test
Plan.
Example: In the below example we can see 2 thread groups one for User Login and Order Creation,
another one is User Login and Product view.
Whenever there is change in the login functionality then we need to ensure that we should update
the login script in both the thread groups.
So instead of duplicate this login in both the thread groups we can define this login functionality in
Test Fragment and use the same in Module controller and put this module controller in both the
thread groups.
22
Page
Now if the login script changes then we can update the login script under Test fragment only…..so
that the both thread groups will work fine.
Configuration Elements:-
It is a simple element where we can collect the Required Information for all the samplers. I.e.
for Web Server Hostname, DB URL, any constants etc.
It will allow us to setup “Defaults” and “Variables” for later use by Samplers.
These are executed at the start, before samplers executes.
These are used to add or modify requests made by samplers.
It can be accessible only from inside where you place the element. For Ex: if we place an HTTP
Cookie Manager inside a simple controller then the Cookie Manager will only be accessible to
HTTP Request which is placed inside the simple controller but not from the outside of logic
controller.
As you can see from the above picture, we can say that the HTTP cookie Manager is place in
inside a simple controller, so now the HTTP requests which are place inside the simple
controller can only access cookie manager. In our case “HTTP Request 1 and HTTP Request
2” can access HTTP Cookie Manager but not Http Request 3 since it is placed outside the
controller. So it is very important where you place your configuration elements.
JMeter provides different types of Configuration Elements and they are
o Counter
o CSV Data Set Config
o FTP Request Defaults
o HTTP Authorization Manager
o HTTP Cache Manager
o HTTP Cookie Manager
23
24
Page
Counter:-
Using this we can create counter that can be used anywhere in the Thread Group.
We can specify the starting point, maximum and increment values in the counters.
We can define variable name which hold counter value, which can be used in the script.
The counter will loop from the start to the max and then start over with the start and continue
like that until the test is ended.
Using this we can create counter and that can be used anywhere in the Thread Group.
During execution of load test we will simulate the real user actions by enter some data like
Customer name in case of “Search Customer” transaction, this can be achieved using CSV data
set config element in JMeter.
This confg element is used to supply random data to JMeter variables from external CSV files.
We can use the same CSV file to supply all the required data for all threads (users) or we can
have different files.
All threads can use separate row data from csv files, starting from line1….line n
Order of picking data from CSV will depend of order of execution of different threads
Need to supply the location of the data file to the JMeter so that JMeter take the values from
the CSV file.
25
Page
Generation of random data at run time is expensive in terms of CPU & Memory usage, so in
general we will create the data in advance of the test and use the same in load testing.
By default the file is opened once and each thread will use different line from the CSV file.
When the end of file (EOF) is reached, and the recycle option is true then the reading starts
again with the first line of the file.
Sharing Mode has
o All Threads – The file is shared between all the threads
o Current Thread Group – Each file is opened once for each thread group.
o Current Thread – Each file is opened separately for each thread.
Data defined in the file should follow the order in which variable names are defined. For
example from the above picture, the variable name order is “UserName”, “Password”, so now
my test data file should like this
This is used when we are going to send the multiple requests to the same FTP server.
EX: We have a script for FTP application and we have around 100 requests for the scenario,
unfortunately the app team moved the FTP server to some other location or changed the
name of the FTP server.
o Now we need to modify our 100 FTP requests to the modified location, suppose if we
have 500 FTP request then?
o So instead of going and modifying the server name in each FTP request, JMeter
provided the FTP Request defaults config element where we can define the location
and port through which we can access the server and perform required operations.
o If we use this element then no need to enter the same information in each FTP request.
The Authorization Manager lets you specify one or more user logins for web pages that are
restricted using server authentication.
When you access some web applications (restricted pages) then the browser will display a
login dialog box to access the application.
JMeter transmits the login information when it encounters this type of pages.
27
Page
JMeter checks each entry in turn and stops when it finds the first match, so we need to
specifies the most specific URL should be appear first in the list.
JMeter ignore the duplicate URL’s.
When we execute a Test Plan, then JMeter looks in the Authorization table for the URL it is
requesting, if the base URL matches the URL in the authorization Manager then JMeter passes
this information along with the request.
It is used to implement browser cache functionality in our test Plan (i.e. to HTTP requests).
Each Virtual User thread has its own cache; by default Cache Manager will store up to 5000
items in cache per Virtual User Thread.
Note that the more you increase this value the more HTTP Cache Manager will consume
memory of the Test controller where you have executing the Load test. If this parameter is too
high, you will easily get an OutOfMemoryException.
28
Page
If we select the check box “Clear Cache Each Iteration” then the JMeter will clear cache at the
start of the thread.
If we select the option “Use Cache-Control/Expires header when processing GET requests”
then the GET request first look into the cache and returns immediately without requesting the
URL from the remote server. This is intended to emulate the browser behavior.
o If the requested document has not changed since it was cached, then the response
body will be empty.
o If the requested document has not changed, than it will be taken from cache. And,
obviously, this will influence response time – it will become much shorter.
HTTP Cache Manager represents browser cache, it means that embedded resources
(images, scripts, styles) are downloaded once and any subsequent calls to these resources do
not trigger HTTP Request to the application or web server and element is returned
immediately from cache. This is how browsers work and this is how you should configure
your JMeter.
When we are accessing any web application in IE/FF/Chrome etc.Browsers and login into the
application then the computer will store this information in a “Cookie”.
Next time if we visit the same website then we don’t need to do the login again because the
browser will use the cookie as user data to login into the web site.
In JMeter HTTP Cookie Manager will do the same like a web browser I.e. if the HTTP request
sends to the server and response contains a cookie then HTTP Cookie Manager will
29
automatically stores that cookie and will use it for all future requests to that particular web
Page
site.
JMeter thread has its own “cookie storage area”. So if we are testing a web site that uses a
cookie for storing session information, then each JMeter thread will have its own session.
o Maintain a separate copy of cookies for each thread.
o It saves cookie value internally; we can’t view that, to view it we need to go to Tree
Listener.
o We can add user defined cookies here.
Header manager entries are merged to form the list for the sampler.
If any entry to be merged matches an existing header name, then it replaces the previous
entry.
So using this we can set up a default set of headers to particular samplers.
This element lets you to set the Default values that the HTTP Request to use. This is similar to
FTP Request Default.
We have created a test plan with 50 HTTP requests and all of the requests are being sent to
the same server. If we add a single HTTP Request Defaults and specify the Server Name or IP
Address and we will update the entire HTTP requests with Server Name field as empty, then
the controller will inherit this field (Server Name or IP Address) from the HTTP Request
30
Default.
If you are sending 100 HTTP request to IRCTC site in a single transaction then we should have
Page
to enter 100 times the server site or IP Address or Server Name for all 100 requests, Instead
of this we can use “The Single HTTP request Defaults” and make the IP Address filed as empty
in the HTTP Request element.
This element lets you to set the Default values for the JAVA testing.
The Database URL and JDBC Driver class are defined by the provider of the JDBC
implementation.
32
Page
This element is used to add or override the user name and password setting in the sampler.
Suppose if we want to execute one user login to gmail.com or facebook.com with username &
password then we can use this element instead of CSV file.
Random Variable:-
This element is used to generate the numeric strings and store them in a variable and use it in
the scripts.
number in between.
If Per thread is FALSE then it is shared between all the threads in the thread group, if it is
Page
Seed for Random function – By default it will take the current time in milliseconds, if we use
same value (Ex: 5) then it will generate same value for each thread.
34
Page
This element is used to define the initial set of variables. Placed at the start of the Thread
Group
If you have more than one Thread Group, then make sure to use different names for the User
Defined Variables.
UDVs are processed in the order they appear in the Plan, from top to bottom.
Timer:-
By default JMeter will send the request without pausing between each request but this is not
exactly realistic. If the continuous requests are sending to the server by JMeter then test
server may hang or server may face overload issues. So to simulate real traffic JMeter
provides Timer elements.
In general user spends some time before submitting a form or moving to next page etc.
We can achieve using Timer element in JMeter.
A timer allows you to define a period to wait between each request.
When we add timer before a sampler (request) then JMeter pauses for that time before
sending a request.
Below are the list of the timers supported by JMeter
o Constant Timer
o Constant Throughput Timer
o Uniform Random Timer
o Gaussian Random Timer
o BeanShell Timer
o Poisson Random Timer
o BSF Timer
35
o JSR223 Timer
o Synchronizing Timer
Page
Constant Timer:-
Using this timer we can delay each user request for the same amount of time.
Here fixed component is called Constant Delay Offset = 1000 ms, Variable component that will
vary between 0ms and the value of field Random Delay Maximum.
Here Total Delay is the sum of the random value + Constant Delay Offset value.
Total Delay Time = Return value of Gaussian Distribution function + Additional value in
millisecond
39
BSF Timer
Between each user request, the BSF Timer can be used to create a delay time using BSF
scripting language.
Synchronizing Timer
This Timer is used to synchronize requests of various threads i.e. It will increase delays
between requests so that all threads fire at the same time there for generating heavy
load bursts on the application.
Pre-Processor Elements:-
It is an element which runs just before a sampler executes.
They are often used to modify the settings of a Sample Request just before it runs. Or update
variables that are not extracted from response text
It is used to perform some action, if it is added to any sampler then it will be used to perform
configuration setting for samplers, it will always execute before sampler.
A Pre-Processor is most often used to modify the settings of a Sample Request just before it
runs, or to update variables that aren't extracted from response text
40
Page
41
Page
This modifier is used to “URL Re-writing to store session id’s instead of cookies” in a request.
This modifier can be added either with sampler or with the Thread Group.
For Example:
o Some web applications that will use session id’s instead of cookies, then this HTTP URL
Re-writing Modifier elementis used to store session id’s. We will give simply the name
of the session id parameter so that the element will on the previous request and add
the value to every request when we add the element at the thread group or to the
particular request where this element is added.
o One of the web application request is sending the below parameters while sending the
request to the server
o Save and run the script then the script will pass.
This preprocessor parses the response of the server & extract links and the forms.
The sampler on which this pre processer is applied, will be examined to see if it matches any of the
link or the forms which is extracted by preprocessor from previous response, if yes then it replace
the value in URL with value hold by preprocessor.
Consider a simple example: let’s say you wanted JMeter to “spider”(Randomly Clicking links in JMeter)
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.
User Parameters:-
This will allows the user to specify values for User Variables specific to Individual Threads.
We can specify these values at the Test Plan but if we want to allows to specify a series of
values for any User Variable then we will use this element.
For each thread the variable will be assigned one of the values from the series in sequence, if
there are more threads than values then values get re-used.
43
Page
JDBC Pre-Processor
This enables us to run some SQL statement just before a sample runs.
This is useful if the JDBC sample requires some data to be in Data Base and we can’t compute
this in a setup Thread group.
o Sampler controller
44
o Logical controller
Page
Samplers:-
Samplers facilitate JMeter to deliver explicit types of requests to the server. I.e. it simulates a
users’ request for a page from the target server so that, to avail POST, GET, DELETE function
on a HTTP service, user can add HTTP Request sampler.
Apart from HTTP sampler, JMeter supports testing of FTP, JDBC, Java Requests, SOAP/XML
Requests, RPC requests.
Sampler specifies the type of the requests i.e. FTP request/HTTP Request/JDBC Request/ etc.
FTP Request:-
If you are doing a performance testing for “FTP” server then we can use FTP request sampler
in JMeter so that this controller lets send an FTP “Download” or “Upload” file request to an
FTP Server
If you want to download a file “Test.txt” from a FTP server then below is the configuration that
we need to do in JMeter
45
Below is the screen shot showing the configuration to download Test.txt file from FTP server.
HTTP Request:-
JDBC Request:-
This sampler allows you to read access logs & generate HTTP request.
The log may be Image/HTML/CSS etc.
SMTP Sampler:-
This sampler allows you to test a Mail Server. Using this sampler we can send email messages
using SMTP protocol to mail server.
Post-Processor Elements:-
46
Response
For example after sending a request to the Web Server (under test) and we will get response,
support if we get an error in the response and would like to stop the test then we will achieve
this using Post Processor
JMeter provides the below Post-Processor elements
o Regular Expression Extractor
o XPath Extractor
o Result Status Action Handler
o JSR223 PostProcessor
o CSS/JQuery Extractor
o BeanShellPostProcessor
o JDBC PostProcessor
o BSF PostProcessor
o Debug PostProcessor
JMeter sends HTTP request to the web server under test www.google.com.
Page
48
Page
e. In this Result Status Action Handle Pane, choose Stop Test Now which will stop the
test if JMeter get the error from server response
f. Now update the HTTP Request Defaults with Server name as www.google.co.in/abc
For Example the Regular Expression for 123 Main St. is \d{1,5}\s\w+\s\w+\.
49
Java provides java.util.regex package for pattern matching with regular expressions.
Page
Regular expression is a special sequence of characters that helps you to match or find strings
or set of strings in the response of a request.
brackets
25 [^…] Matches any single character not in
brackets
26 \A Matches Beginning of string
27 \z Matches End of string
28 \Z Matches end of string except allowable
final line terminator.
29 re* Matches 0 or more of the previous X* – X, zero or more times
thing
30 re+ Matches 1 or more of the previous X+ – X, once or more time
thing
31 re? Matches 0 or 1occurrence of preceding X? – X, once or not at all
expression
32 re{n} Matches exactly n number of X{n} – X, exactly n times
occurrences of preceding expression.
33 re{n,} Matches n or more occurrences of X{n,}-X at least n times
preceding expression.
34 re{n,m} Matches at least n and at most m X{n,m} – X, at least n but
occurrences of preceding expression. not more than m times
35 a|b Matches either a or b
36 (re) Group regular expressions and
remembers matched text
37 (?:re) Groups regular expressions without For grouping
remembering matched text.
38 Matches independent pattern without
(?> re)
backtracking.
39 \w Matches word characters.
40 \W Matches nonword characters.
41 \Q Escape (quote) all characters up to \E
42 \E Ends quoting begun with \Q
43 [abc] a,b , or c
44 [^abc] Any character except a, b or c
45 [a-zA-Z] A through z, or A through Z (range)
46 [a-d[m-p]] a through d, or m through p
47 [a-z&&[^bc]] a through z, except for b and c
[ad-z] subtraction
48 [a-z&&[^m-p]] a through z, and not m through p
[a-lq-z] subtraction
51
Page
Few Examples:-
Simple
Negation
Ranges
Unions
Intersections
No match found.
Subtraction
Assertions play an import role in testing i.e. It’s allow us to include some validations in the
test on the response of the request which is made using Sampler.
Using assertions we can prove that the application is returning the correct data or It helps to
verify and ensure that testing process is going in a right direction and the server which is
under test returns the expected results.
o For EX: User sends a request to the server
o Server process the request and send the response to the client after some duration
o How user will be ensuring that the coming response from the server is the correct one?
o To resolve this issue, we will use assertions or verification to ensure that the response
comes from the server at run time is correct.
o If response is not correct then the test will get fail for that request
JMeter highlights when an assertion fails.
Below are the assertions available in JMeter
o Bean Shell Assertion
o BSF Assertion
o Compare Assertion
o Duration Assertion
o HTML Assertion
o JSR233 Assertion
o MD5Hex Assertion
o Response Assertion
o Size Assertion
o SMIME Assertion
o XML Assertion
o XML Schema Assertion
o XPath Assertion
Response Assertion
This Assertion will add pattern strings to be compared against various fields of the
server response.
After sending any request we will get response after some time, now using this
Response Assertion we can verify that the response contains expected pattern string
like “OK” or “Google” etc.
59
Page
Duration Assertion
This duration Assertion tests that each server response was received within a given
amount of time or not
This Assertion will add verify that “Each response comes from the server has received
within a given amount of time or not.
If any server response takes longer time than the given number of milliseconds
specified by the user then the response get fails.
60
Page
Size Assertion
The size Assertion tests that each server response contains the expected number of
bytes in it.
We can specify the size is equal, greater than, less than, not equal to the given number
of bytes.
XML Assertion
The XML Assertion tests that the response data consists of a formally correct XML
document or not.
61
Page
HTML Assertion
The HTML Assertion allows user to check the HTML syntax of the response data. i.e.
the response data must be met the HTML syntax.
HTML Assertion
The XML Assertion allows user to check the HTML syntax of the response data. i.e. the
response data must be met the HTML syntax.
63
Code
65
When you ready to run test, click Run button on the menu bar
The test result will display on Assertion Results pane. If Google server response code
contains the pattern 302, the test case is passed. You will see the message displayed as
follows:
Now back to Response Assertion Panel, you change the Pattern to test to from 302 to 500.
Because Google server response code doesn't contain this pattern, you will see the test case
66
Failed as following….
Page
Listeners:-
Listeners facilitate viewers to view Samplers results in different forms. I.e. Listeners will show
the results of the test execution.
Listeners offer to collect, save and view the results of a test plan and store results in XML
format or CSV format.
The output can also be viewed directly within the JMeter console.
We can add these listeners anywhere in the test.
Different formats like “Table/Tree/Graph/Log file etc. will be available in JMeter
o Graph result listeners will display the Server Response Times on a Graph
o Tree will show the results in basic HTML format
o Table will show the summary of the test results in table format
o Log will show the summary of the test results in text file….
JMeter provides the below Listeners
o Graph Results
o Spline Visualizer
o Assertion Results
o Simple Data Writer
o Monitor Results
o Distribution Graph (alpha)
o Aggregate Graph
o Mailer Visualizer
o Bean Shell Listener
o Summary Report
67
Logical Controllers:-
Logical controllers decide the order of processing of samplers in a Thread. It’s a mechanism to
control the flow of the thread group.
Logical controllers can alter the order of requests coming from their child elements.
Logical Controllers define the order of processing requests in a thread. i.e. It facilitates users
to describe the sequence of processing request sends to the server in a Thread
EX: We can use “Random Controllers to send HTTP requests to the server randomly
JMeter provides the below logical controllers
a. Recording Controller
b. Simple Controller
c. Loop Controller
d. Random Controller
e. Module Controller
Recording Controller
JMeter can record our testing steps.
It is a place holder to store the recording steps.
68
Page
Simple Controller
It is a simple controller it holds the user requests i.e. It is a container for user requests
Loop Controller
Using this controller user can run the request for specified number of times or forever.
69
Page
Random Controller
Using this controller user can run the request in Random Order in each loop period.
If we have 3 requests in our script….
a. HTTP Request
b. FTP Request
c. JDBC Request
Each request runs 5 times
a. i.e. HTTP Request runs 5 Times
b. FTP Request runs 5 times
c. JDBC Request runs 5 times
For each Loop user request send Sequentially then the order of the request is
a. HTTP Request-- FTP Request-- JDBC Request
If user send the requests Randomly then
a. FTP Request-- HTTP Request-- JDBC Request
b. JBDC Request-- FTP Request-- HTTP Request
Module Controller
Using this controller we can add modularity to JMeter.
Any web application has “Sign-in, Search, Add Customer, and Logout”. This functionality can
be stored in “Simple Controller” as modules.
Module controller will choose which module needs to run….
70
Page
If we want to simulate
o Runtime Controller
The Runtime Controller controls how long its children are allowed to run.
72
Page
o IFController
The If Controller allows the user to control whether the test elements below it
are run or not.
o Transaction Controller
Evaluates the overall time taken to complete a test execution.
In JMeter each HTTP request is represented by a separate request i.e. Images,
styles, scripts etc. So for 1 web page we have N number of samples i.e. N is
always > 1. This doesn't reflect real page load time in the report.
Real Time Scenario Open Product Search Page → Select a Product → Proceed to
Checkout Page → Checkout.
The Transaction Controller which generates a “virtual” sample to measure
transaction times.
73
Page
Look in to above example, There are 2 main HTTP requests. 1. Home Page and
2. FAQ Page. .jpg request, .gif request, .png request and .js request are the sub
requests of Home Page. On completion of recording, i added Transaction
Controller and moved all requests of home page under it. I set 2 virtual users in
thread group and added Aggregate Report Listener to view test results.
74
Page
o While Controller
The While Controller runs its children until the condition is "false".
o Switch Controller
"Switch Controller" is one of the Logic Controller of Apache Jmeter. As name
suggest, You can switch your targeted software application page request to run
using Switch Controller. You can set your required request id in Switch
Controller to execute it so all other requests under Switch Controller will be
neglected during execution.
Suppose i recorded apache jmeter testing script for 4 pages -> 1. Home Page, 2.
My Account Page, 3. Login Page and 4. FAQ Page. Now supposing temporarily i
do not want to perform load testing on 'My Account Page'. Then what i can do?
75
1st idea is i will remove that request from load test script and then run test. 2nd
Page
I set Number of Thread = 3 and Loop Count = 2 in thread group property and
set Switch Value = 0 in Switch Controller property. I run this test and viewed
results in View Results Tree listener as bellow.
76
See in above image, any request of 'My Account Page' is not display in result
Page
execute only 1st request from all requests under switch controller. If i set
Switch Value =1 then all 3 virtual users of Apache jmeter will execute only My
Account Page request. Create script with multiple pages under Switch
Controller for your software application and try above example with different
Switch Values.
o ForEach Controller
o Module Controller
o Include Controller
o Loop Controller
o Once Only Controller
o Interleave Controller
o Random Controller
o Random Order Controller
o Throughput Controller
77
Page
Configuration Elements
Pre-Processors
Timers
Sampler
Post-Processors (unless Sample Result is null).
Assertions (unless Sample Result is null)
Listeners (unless Sample Result is null)
Test Plan
A test plan contains a series of Elements that are useful in application testing process.
Elements are Thread Group, Logic Controllers, Sample Generating Controllers, Listeners,
Timers, Assertions and Configuration elements.
Test Plan holds many elements
78
Page
Work Bench
It’s a place which creates space to store test elements temporarily at the time of constructing
test.
In general while designing the Test Script we will do it in Work bench, once it is working fine
then we will move it to Test Plan.
JMeter saves only the content of Test Plan but not the Work Bench.
Adding Elements
In the similar manner we can add ‘n’ number of elements in the Test Plan.
Removing Elements
Similar to adding we can also remove the unwanted/unused elements from the Test Plan by
simply right click and Remove.
Saving Elements
In JMeter we can save entire Test Plan or only the required elements.
In both the cases the JMeter saves the files with “.JMX” format.
Saving an Element as below 80
Page
81
Page
Add the required Element, which will be under Test Plan in the left pane of JMeter GUI
Do the configuration changes on the right side of the element.
For running of a Test Plan, just click on the RUN button at Top right side corner in the menu
item.
GUI – Green button
possible
o Second – Click on Stop or “Control + ,” This appeals the threads to stop at the end of
any present work.
Performance Testing:-
JMeter provides the following benefits to the system or application under Performance Test
o JMeter is useful to test the performance of static resources such as “Java Script &
HTML, Dynamic resources – JSP, Servlets & AJAX.
o JMeter is useful to find the maximum number of simulated users that use the websites.
o JMeter is useful to provide a various graphical analysis of Performance Reports.
The required information is “Number Users i.e. Threads, Ramp-Up Period, Iterations i.e. Loop
count” etc.
If Number of Threads = 100, Loop Count = 10, then JMeter simulates 100 simultaneous users
trying to connect to the target server or website and each user trying to connect the targeted
server 10 times.
After thread group we need to specify the Type of the Request with which we can connect the
84
Now we are adding HTTP request Default Element, and enter the Server Name or IP Address
of the target server
Now after opening the google page we need search for anything, support we want to search
for the Performance Testing then we need to enter the text as “Performance Testing” in search
field. This can be done in JMeter by adding a HTTP Requests “
Add -> Sampler -> HTTP Request.
Now enter the required text in the path filed
85
Page
Results Format
Before executing the test, we need to add the results format in JMeter so that we can view the
results while executing the test.
Add -> Listener -> View Results Tree.
Add both Graph results and Table results
86
Page
These loop controller helps samplers to execute specific number of times with the defined
value for the Thread Group.
Example:-
a. Add one HTTP Request to a Loop Controller with a loop count 50
b. Now configure the Thread Group Loop count to 2, then JMeter will send a total of 50 *
2 = 100 HTTP Requests.
88
Page
ii. In this example, total request sending to the server is 2 * 50 = 100 HTTP Request.
iii. Now add HTTP request to the Loop Controller, Right click Loop Controller, Add ->
Sampler -> HTTP request
89
Processor in JMeter
Processors are used to modify the Samplers as per their scope.
There 2 Types of Processors
a. Pre-Processor
b. Post-Processor
In some situations when you have to extract response from one request and pass it on to another
request. This can be accomplished using regular expression extractor in JMeter.
http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
JMeter Functions
Below table having list of functions available in JMeter are…
Time Function
Most of the times we will use different date and time values in the JMeter script, we will get these
values using time function.
${__time(dd/MM/yyyy,)}
${__time(hh:mm a,)}
${__time(dd-mmm-yyyyHHmmss)} 20-032-2015 233224
${__time(d-MMM-yyyyhhmmss)} 20-May-2015 113224
${__time(dd-m-yyyyhhmmss)} 20-32-2015 113224
${__time(D-M-yyyyhhmmss)} 140-5-2015 113224
${__time(DD-MM-yyyy)} 140-05-2015
Sometimes we need to use time in UTC time zone format then we need to use
${__time(yyyy-MM-dd'T'hh:mm:ssX)}
In one of the script the date value as 13th Nov 2012 17:00 would by 20121113170000, then
the corresponding time function is ${__time(yyyyMMddHMS). Suppose we would use the
same value in different places then we can store this data value in a variable as
${__time(yyyyMMddHMS,DateVariable)
92
Page