0% found this document useful (0 votes)
6 views34 pages

Jmeter Tutorial

JMeter is an open-source Java application designed for load and performance testing, supporting various test types like functional, regression, and stress testing. This tutorial aims to provide software professionals with a comprehensive understanding of the JMeter framework, including prerequisites, installation steps, and how to build and run test plans. Key features of JMeter include its platform independence, multi-threading capabilities, and support for various protocols.

Uploaded by

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

Jmeter Tutorial

JMeter is an open-source Java application designed for load and performance testing, supporting various test types like functional, regression, and stress testing. This tutorial aims to provide software professionals with a comprehensive understanding of the JMeter framework, including prerequisites, installation steps, and how to build and run test plans. Key features of JMeter include its platform independence, multi-threading capabilities, and support for various protocols.

Uploaded by

Mauro
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JMeter Tutorial

jMeter is an Open Source testing software. It is 100% pure Java application for load and
performance testing.

jMeter is designed to cover categories of tests like load, functional, performance, regression,
etc., and it requires JDK 5 or higher.

This tutorial will give you great understanding on jMeter framework needed to test an
enterprise level application to deliver it with robustness and reliability.

Audience
This tutorial is designed for Software Professionals, who are willing to learn jMeter
Framework in simple and easy steps. This tutorial will give you great understanding on
jMeter Framework concepts, and after completing this tutorial, you will be at intermediate
level of expertise from where you can take yourself to higher level of expertise.

Prerequisites
Before proceeding with this tutorial, you should have a basic understanding of Java
programming language, text editor and execution of programs, etc., because you are going
to use jMeter to handle all levels of Java project testing (regression, functional, load,
performance, etc.,), so it will be good if you have knowledge of software development and
software testing processes.
Table of Content
Overview............................................................................................................................5
What is JMeter?.............................................................................................................5
JMeter Features.............................................................................................................6
How JMeter Works?......................................................................................................6
Environment......................................................................................................................7
System Requirements....................................................................................................7
Step 1 - verify Java installation in your machine............................................................7
Step 2: Set JAVA environment.......................................................................................8
Step 3: Download JMeter..............................................................................................8
Step 4: Run JMeter.........................................................................................................8
Build Test Plan.................................................................................................................10
What is a Test Plan?.....................................................................................................10
Start the JMeter Window.............................................................................................10
Add/Remove Elements................................................................................................11
Loading and Saving Elements.......................................................................................12
Configuring Tree Elements...........................................................................................13
Saving the Test Plan.....................................................................................................13
Running a Test Plan......................................................................................................14
Stopping a Test............................................................................................................14
Test Plan Elements...........................................................................................................15
ThreadGroup................................................................................................................15
Controllers...................................................................................................................16
Samplers......................................................................................................................16
Logic Controllers..........................................................................................................17
Test Fragments............................................................................................................19
Listeners.......................................................................................................................19
Timers..........................................................................................................................19
Assertions....................................................................................................................20
Configuration Elements...............................................................................................21
Pre-Processor Elements...............................................................................................22
Post-Processor Elements.............................................................................................23
Execution order of Test Elements................................................................................23
Listeners..........................................................................................................................25
Default Configuration..................................................................................................25
CSV Log format............................................................................................................26
Saving response data...................................................................................................27
Loading (reading) response data..................................................................................27
Saving Listener GUI data..............................................................................................27
Apache JMeter HTTP(S) Test Script Recorder..................................................................28
Jmeter configuration.......................................................................................................28
Basic Instructions............................................................................................................28
Apache JMeter HTTP(S) Test Script Recorder..................................................................29
Jmeter configuration....................................................................................................29
Basic Instructions.............................................................................................................30
Configure your browser to use the JMeter Proxy............................................................33
Record your navigation....................................................................................................34
Start the test....................................................................................................................36
Overview

B efore digging into the JMeter, let us first understand few jargons mostly associated with the testing of any

application.

 Performance Test: This test sets the „best possible‟ performan infrastructure. It also highlights early in the testing process if
changes need to be made before application
goes into production.
 Load Test: This test is basically used for exercising\discovering the system under the top load it was
designed to operate under.
 Stress Test: This test is an attempt to break the system by overwhelming its resources.

What is JMeter?
JMeter is a software allowing to load test or performance oriented business (functional) test on different protocols
or technologies. Stefano Mazzocchi of the Apache Software Foundation was the original developer of JMeter. He
wrote it primarily to test the performance of Apache JServ (Now called as Apache Tomcat project). Apache later
redesigned JMeter to enhance the GUI and to add functional-testing capabilities.

This is a Java desktop application with a graphical interface using the Swing graphical API, can therefore run on
any environment / workstation accepting a Java virtual machine, for example: Windows, Linux, Mac, etc.

The protocols supported by JMeter are:

 Web: HTTP, HTTPS sites 'web 1.0' web 2.0 (ajax, flex and flex-ws-amf)

 Web Services: SOAP / XML-RPC

 Database via JDBC drivers

 Directory: LDAP

 Messaging Oriented service via JMS

 Service: POP3, IMAP, SMTP

 FTP Service
JMeter Features
Following are some of the features of JMeter:

 Its free. Its an open source software.

 It has simple and intuitive GUI.

 JMeter can load and performance test many different server types: Web - HTTP, HTTPS, SOAP, Database via
JDBC, LDAP, JMS, Mail - POP3

 It is platform-independent tool. On Linux/Unix, JMeter can be invoked by clicking on JMeter shell script. On
Windows it can be invoked by starting the [Link] file.

 It has full Swing and lightweight component support (precompiled JAR uses packages [Link].* ).

 JMeter store its test plans in XML format. This means you can generate a test plan using a text editor.

 It's full multi-threading framework allows concurrent sampling by many threads and simultaneous sampling of
different functions by separate thread groups.

 It is highly Extensible.

 Can also be used to perform automated and functional testing of your application.

How JMeter Works?


JMeter simulates a group of users sending requests to a target server, and return statistics that show the
performance/functionality of the target server / application via tables, graphs etc. The figure below depicts this process:
Environment

J Meter is a framework for Java, so the very first requirement is to have JDK installed in your machine.

System Requirements
JDK 1.6 or above.

Memory no minimum requirement.

Disk Space no minimum requirement.

Operating System no minimum requirement.

Step 1 - verify Java installation in your machine


Now, open console and execute the following java command.

OS Task Command

Windows Open Command Console c:\> java -version

Let's verify the output for the windows operating system

Output

My windows
If you do not have Java installed, install the Java Software Development Kit (SDK)
from[Link] We are assuming Java 1.7.0_25 as
installed version for this tutorial.

Step 2: Set JAVA environment


Set the JAVA_HOME environment variable to point to the base directory location, where Java is installed on
your machine. For example;
OS Output

Windows Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.7.0_25

Append Java compiler location to System Path.

OS Output

Append the string; C:\Program Files\Java\jdk1.7.0_25\bin to the end of the system variable,
Windows
Path.

Verify Java Installation using java -version command explained above.

Step 3: Download JMeter


Download latest version of JMeter from [Link] At the time of writing this
tutorial, I downloaded apache-jmeter-2.9 and copied it into C:\>JMeter folder.

The directory structure should look like as below:

 apache-jmeter-2.9

 apache-jmeter-2.9\bin

 apache-jmeter-2.9\docs

 apache-jmeter-2.9\extras

 apache-jmeter-2.9\lib\

 apache-jmeter-2.9\lib\ext

 apache-jmeter-2.9\lib\junit

 apache-jmeter-2.9\printable_docs

You can rename the parent directory (i.e. apache-jmeter-2.9) if you want, but do not change any of the sub-
directory names.

Step 4: Run JMeter


Once the you download the JMeter, goto to the bin directory. In our case it would be/home/manisha/apache-
jmeter-2.9/bin. Now click on the following:
OS Output

Windows [Link]

Once clicked on the above file, after a short pause, the JMeter GUI should appear which is a Swing application
as seen in the image below:

This is the main page and default page of the tool.

Build Test Plan


What is a Test Plan?

A Test Plan defines and provides a layout of how and what to test. For example the web application as

well as the client server application. It can be viewed as a container for running tests. A complete test plan will
consist of one or more elements such as thread groups, logic controllers, sample-generating controllers, listeners,
timers, assertions, and configuration elements. A test plan must have at least one thread group. We shall discuss
these elements in detail in the next chapter Test Plan Elements.

Follow the below steps to write a test plan:

Start the JMeter Window


Open the JMeter window by clicking on /home/manisha/apache-jmeter-2.9/bin/[Link]. The JMeter window
will appear as below:
This is a JMeter window having nothing added yet. Details of the above window are:

 Test Plan node is where the real test plan is kept.

 Workbench node simply provides a place to temporarily store test elements while not in use, for copy/paste
purposes. When you save your test plan, WorkBench items are not saved with it.

Add/Remove Elements
Elements (which will be discussed in the next chapter Test Plan Elements) of a test plan can be added by right
clicking on the Test Plan node and choosing a new element from the "add" list.

Alternatively, elements can be loaded from file and added by choosing the "merge" or "open" option.

For example let's add a Thread Group element to a Test Plan as shown below:

To remove an element, make sure the element is selected, right-click on the element, and choose the "remove"
option.
Loading and Saving Elements
To load an element from file, right click on the existing tree element to which you want to add the loaded element,
and select the "merge" option. Choose the file where your elements are saved. JMeter will merge the elements into
the tree.

To save tree elements, right click on an element and choose the Save Selection As ... option. JMeter will save
the element selected, plus all child elements beneath it. By default JMeter doesn't save the elements, you need
to explicitly save it as mentioned earlier.
Configuring Tree Elements
Any element in the Test Plan can be configured in the controls present in JMeter's right-hand frame. These
controls allow you to configure the behavior of that particular test element. For example the Thread Group can be
configured for number of users, ramp up period etc as below:

Saving the Test Plan


You can save an entire Test Plan either by using Save or "Save Test Plan As ..." from the File menu.
Running a Test Plan
You can run your Test Plan choosing Start (Control + r) from the Run menu item. When JMeter is running, it
shows a small green box at the right hand end of the section just under the menu bar.

The numbers to the left of the green box are the number of active threads / total number of threads. These only
apply to a locally run test; they do not include any threads started on remote systems when using client-server
mode.

Stopping a Test
You can stop your test in two ways:

 Using Stop (Control + '.'). This stops the threads immediately if possible.
 Using Shutdown (Control + ','). This requests the threads to stop at the end of any current work.
Test Plan Elements

A JMeter Test Plan comprises of test elements which are discussed below. A Test Plan would comprise

at least one Thread Group. Within each Thread Group we may place a combination of one or more of other
elements: Sampler, Logic Controller, Configuration Element, Listener, and Timer. Each Sampler can be preceded
by one or more Pre-processor element, followed by Post-processor element, and/or Assertion element. Let's see
each of these elements in detail:

ThreadGroup
Thread Group elements are the beginning points of your test plan. As the name suggests, the thread group
elements control the number of threads JMeter will use during the test. We can also control the following via the
Thread Group:

 By setting the number of Threads.

 By setting the Ramp Up Time

 By setting the number of test iterations.

The Thread Group Control Panel looks like this:


Details of each component on the above panel are:

 Action to be taken after a Sampler error: In case any error occurs during test execution you may let the
test either:
o Continue to the next element in the test o
Stop Thread to stop the current Thread.
o Stop Test completely, in case you want to inspect the error before continue running.
 Number of Threads: Simulates the number of user(s) or connection(s) to your server application.
 Ramp-Up Period: Defines how long it will take JMeter to get all threads running.
 Loop Count: Defines the number of times to execute the test.
 Scheduler checkbox Once selected, the Scheduler Configuration section will appear at the bottom of the
control panel.
 Scheduler Configuration You can configure the start and end time of running the test.

Controllers
JMeter has two types of Controllers: Samplers and Logic Controllers.

Samplers
Samplers allow JMeter to send specific types of requests to a server. They simulate a user's request for a page
from the target server. For example, you can add a HTTP Request sampler if you need to perform a POST, GET,
DELETE on a HTTP service

Some useful samplers are:

 HTTP Request

 FTP Request

 JDBC Request

 Java Request
 SOAP/XML Request

 RPC Requests

An HTTP Request Sampler Control Panel looks like the following figure:

Logic Controllers
Logic Controllers let you control order of processing of Samplers in a Thread. Logic Controllers can change the
order of request coming from any of their child elements. Some examples are: ForEach Controller, While
Controller, Loop Controller, IF Controller, Run Time Controller, Interleave Controller, Throughput Controller, Run
Once Controller.

A Loop Controller Control Panel looks like the following figure:


The following list consists of all the Logic Controllers JMeter provides:

 Simple Controller

 Loop Controller

 Once Only Controller

 Interleave Controller

 Random Controller

 Random Order Controller

 Throughput Controller

 Runtime Controller

 If Controller

 While Controller

 Switch Controller

 ForEach Controller

 Module Controller

 Include Controller

 Transaction Controller
 Recording Controller

Test Fragments
Test Fragments is a special type of element placed at the same level as Thread Group element. It is distinguished
from a Thread Group in that it is not executed unless it is referenced by either a Module Controller or an
Include_Controller. This element is purely for code re-use within Test Plans.

Listeners
Listeners let you view the results of Samplers in the form of tables, graphs, trees or simple text in some log files.
They provide visual access to the data gathered by JMeter about the test cases as a Sampler component of
JMeter is executed.

Listeners can be added anywhere in the test, including directly under the test plan. They will collect data only from
elements at or below their level. The following list consists of all the Listeners JMeter provides:

 Sample Result Save Configuration

 Graph Full Results

 Graph Results

 Spline Visualizer

 Assertion Results

 View Results Tree

 Aggregate Report

 View Results in Table

 Simple Data Writer

 Monitor Results

 Distribution Graph (alpha)

 Aggregate Graph

 Mailer Visualizer

 BeanShell Listener

 Summary Report

Timers
By default, a JMeter thread will send requests without pausing between each sampler. This may not be what you
want. We can add a timer element which will allow us to define a period to wait between each request.
The following list consists of all the Timers JMeter provides:

 Constant Timer

 Gaussian Random Timer

 Uniform Random Timer

 Constant Throughput Timer

 Synchronizing Timer

 JSR223 Time

 BeanShell Time

 BSF Time

 Poisson Random Time

As an example, the Constant Timer Control Panel looks like this:

Assertions
Assertions allow you to include some validation test on the response of your request made using a Sampler. Using
assertions you can prove that your application is returning the correct data. JMeter will highlight when an assertion
fails.

The following list consists of all the Assertions JMeter provides:

 Beanshell Assertion
 BSF Assertion

 Compare Assertion

 JSR223 Assertion

 Response Assertion

 Duration Assertion

 Size Assertion

 XML Assertion

 BeanShell Assertion

 MD5Hex Assertion

 HTML Assertion

 XPath Assertion

 XML Schema Assertion

As an example, the Response Assertion Control Panel looks like this:

Configuration Elements
Configuration Elements allow you to create defaults and variables to be used by Samplers. They are used to add
or modify requests made by Samplers.
They are executed at the start of the scope of which they are part, before any Samplers that are located in the
same scope. Therefore, a Configuration Element is accessed only from inside the branch where it is placed.

The following list consists of all the Configuration Elements JMeter provides:

 Counter

 CSV Data Set Config

 FTP Request Defaults

 HTTP Authorization Manager

 HTTP Cache Manager

 HTTP Cookie Manager

 HTTP Proxy Server

 HTTP Request Defaults

 HTTP Header Manager

 Java Request Defaults

 Keystore Configuration

 JDBC Connection Configuration

 Login Config Element

 LDAP Request Defaults

 LDAP Extended Request Defaults

 TCP Sampler Config

 User Defined Variables

 Simple Config Element

 Random Variable

Pre-Processor Elements
A Pre-Procesor is something that will happen before a sampler executes. They are often used to modify the
settings of a Sample Request just before it runs, or to update variables that are not extracted from response text.

The following list consists of all the Pre-Processor Elements JMeter provides:

 HTML Link Parser


 HTTP URL Re-writing Modifier

 HTTP User Parameter Modifier

 User Parameters

 JDBC PreProcessor

 JSR223 PreProcessor

 RegEx User Parameters

 BeanShell PreProcessor

 BSF PreProcessor

Post-Processor Elements
A Post Processor executes after a sampler finishes its execution. This element is most often used to process the
response data, for example, to retrieve particular value for later use.

The following list consists of all the Post-Processor Elements JMeter provides:

 Regular Expression Extractor

 XPath Extractor

 Result Status Action Handler

 JSR223 PostProcessor

 JDBC PostProcessor

 BSF PostProcessor

 CSS/JQuery Extractor

 BeanShell PostProcessor

 Debug PostProcessor

Execution order of Test Elements


Following is the execution order of the test plan elements:

1. Configuration elements

2. Pre-Processors

3. Timers

4. Sampler
5. Post-Processors (unless SampleResult is null)

6. Assertions (unless SampleResult is null)

7. Listeners (unless SampleResult is null)


Listeners

L isteners provide access to the information JMeter gathers about the test cases while JMeter runs. The

results or information gathered by listeners can be shown in the form of:

 tree

 tables

 graphs

 log file

All listeners write the same raw data to the output file when one is specified.

Default Configuration
The default items to be saved can be defined:

 in the [Link] (or [Link]) file. This file is present in the /bin folder of [Link] change the
default format, find the following line in [Link]:

[Link].output_format=

 or by using the Config popup as shown in the image below:


JMeter creates results of a test run as JTL (JMeter Text Logs). These are normally called JTL files, as that is the
default extension - but any extension can be used.

If multiple tests are run using the same output file name, then JMeter automatically appends new data to the end of
the file.

The listener can record results to a file but not to the UI. It is meant to provide an efficient means of recording data
by eliminating GUI overhead.

When running in:

 GUI mode: use the listener Simple Data Writer


 non-GUI mode: the -l flag can be used to create a data file.

Listeners can use a lot of memory if there are a lot of samples. To minimise the amount of memory needed, use
the Simple Data Writer, and use the CSV format.

CSV Log format


The CSV log format depends on which data items are selected in the configuration. Only the specified data items
are recorded in the file. The order of appearance of columns is fixed, and is as follows:

Field Description Value Example

timeStamp in milliseconds since 1/1/1970 1354223881017

elapsed in milliseconds 1858

label sampler label HTTP Request

responseCode e.g. 200, 404 200

responseMessage e.g. OK OK
threadName Thread Group 1-1

dataType e.g. text text

success true or false true

failureMessage if any

bytes number of bytes in the sample 34908

grpThreads number of active threads in this thread group 1

allThreads total number of active threads in all groups 1

URL [Link]

Filename if Save Response to File was used

latency time to first response 132

encoding utf-8

SampleCount number of samples (1, unless multiple samples are aggregated) 1

ErrorCount number of errors (0 or 1, unless multiple samples are aggregated) 0

Hostname where the sample was generated LaptopManisha

IdleTime number of milliseconds of 'Idle' time (normally 0)

Variables if specified

Saving response data


The response data can be saved in the XML log file if required. But it has constraints, when the file is large and
also images cannot be included. In such cases use the Post-Processor Save_Responses_to_a_file . This
generates a new file for each sample, and saves the file name with the sample. The file name can then be included
in the sample log output. The data will be retrieved from the file if necessary when the sample log file is reloaded.

Loading (reading) response data


To view an existing results file, you can use the File "Browse..." button to select a file. If necessary, just create a
dummy testplan with the appropriate Listener in it.

Saving Listener GUI data


JMeter is capable of saving any listener as a PNG file. To do so, select the listener in the left panel,
Edit > Save As Image.

A file dialog will appear. Enter the desired name and save the listener.
Apache JMeter HTTP(S) Test Script Recorder
This tutorial attempts to explain the exact steps for recording HTTP/HTTPS. For those new
to JMeter, one easy way to create a test plan is to use the Recorder.

Jmeter configuration
Since JMeter 2.10, recording has been improved to better handle embedded resources
and creation of certificates on the fly.
To enable these features, JMeter uses keytool utility (available in JRE/JDK) so you need to
ensure your configuration is correct, read this wiki page before starting:

• [Link] Note that recording is more powerful


with a Java 7.

Basic Instructions
1. Go to JMETER_HOME/binand start JMeter with [Link]
2. Select “Test Plan” on the tree
3. Right click on the “Test Plan” and add a new thread group: Add > Threads (Users) >
Thread Group

4. Select the Thread Group


5. Right click “Add -> ConfigElement -> HTTP Request Defaults”
6. In new HTTP Request Defaults element: Server name – enter “[Link]”
7. Path – leave blank

1. Right click on the “Thread Group” and add a recording controller: Add > Logic Controller >
Recording Controller
9. Next, select WorkBench
10. Right click on WorkBenchand add the recorder: Add -> Non-Test Elements -> HTTP(S)
Test Script Recorder

11. On HTTP(S) Test Script Recorder, click the “Add” button in “URL Patterns to Include”.
This will create a blank entry; enter “.*\.html”.
12. Right click on “HTTP(S) Test Script Recorder” and add a listener: Add -> Listener -> View
Results Tree

13. Return to HTTP(S) Test Script Recorder, and click the “Start” button at the bottom.

This will start the JMeter proxy server which is used to intercept the browser requests.
A file called [Link] will be generated in jmeter/bin folder.
Install this certificate in your browser, if you don't know how to do it, read “ Installing the
JMeter CA certificate for HTTPS recording” in :

• [Link]
%29_Test_Script_Recorder

Configure your browser to use the JMeter Proxy


At this point, JMeter'sproxy is running. For this exercise, we will use Iceweasel/Firefox to
view some pages on the JMeter website.

14. Start Firefox, but do not close JMeter.


15. From the tool bar, click “Edit -> Preferences” (or “Tools > Preferences”). This should bring
up the options.
16. Select the “Advanced” tab, and “Network” tab
17. Click “Settings” button near the bottom.
18. On the new pop-up, check “Manual proxy configuration”. The address and port fields
should be enabled now.
19. Address – enter “localhost” or the IP address of your system
20. Port – enter “8080”.
21. Check “Use this proxy server for all protocols”

22. Click “OK” button


23. Click “OK” button again. This should return you to the browser

Record your navigation

24. With your browser, in the “Address” bar at the top, enter
“[Link] and hit the “enter” key.
25. Click on a few links on JMeter'spages.
26. Close your browser and bring up the JMeter window.

Expand the thread group and there should be several samplers. At this point, the test plan can be
saved as is. If you forget to add default HTTP Request settings, you will have to manually delete the
server name, and port.
In this sample, there aren't any default request parameters. If a particular request parameter
is required by all pages, the request defaults is where one would add the entries.

27. Select “Thread Group”


28. Right click “Add -> Listener -> Summary Report” to add an summary listener.
29. The summary listener will show some basic statistics.
Select “Thread Group”
30. Number of Threads – enter “5”
31. Ramp up Period – do not change
32. Loop Count – enter 100

Start the test


At this point, we are ready to run our test plan and see what happens. Save the test plan.
When you're ready to run the test, there's two ways:
1. Run -> Start
2. Ctrl–R

Before you start the test, select “Summary Report”. As the test runs, the statistics will change
until the test is done. At the end of the test, the summary report should look like this.

While the test is running, in the upper right-hand corner, there should be a green square.
When the test is done, the box should be grey.

You might also like