Complete overview of JMeter Elements with examples of when to use them

JMeter has a very complex architecture that provides support for several inbuilt elements and allows extending the functionality of JMeter through plugins. It has many elements like Samplers, Processors, Listeners etc. In simple terms, different types of Elements represent the different features provided by JMeter.

In this topic, we will provide a brief overview of the most commonly used elements in JMeter and their features. In the subsequent topics, we will go into details of the elements and learn how to use them through practical hands on exercises.

It can be confusing to study all the components of JMeter at once. In case you do not understand some of the elements in this topic, do not worry, you will become familiar with them when we take up each one in detail.

The following figure shows the basic elements of JMeter.Introduction_to_Basic_Elements_JMeter

Test Plan

If you want to execute a performance test, you need a test plan. Test Plan in JMeter looks like a test script or a container for test execution. It describes a series of test steps, which JMeter will execute and run.

Test Plan is the biggest elements of JMeter. As shown in the above figure, Test Plan is a root element in JMeter architecture and is at the top of the hierarchy.

A complete test plan consists of one or many elements such as Thread Group, Samplers, Listeners, Timers etc. There is one point to be noted here: A Test Plan always has at least one Thread Group.

Thread Groups

Thread Group is the most basic element of any Test Plan. It controls all the threads that JMeter uses to execute the test cases. Thread Groups are the starting point of a Test Plan.

Example: Let consider following scenario. During a promotional campaign, 1000 real users connect concurrently to the server and use your web application. Each user will create a working session to that web application.JMeter_User_Load_Testing

JMeter defines that session as a Thread. Each thread simulates a real user who connects to the web server. Thread Group is a set of those threads.

JMeter allows Thread Group to be configured as follows:

  • Simulate number of real users connected to the web server by defining the number of threads in Thread Group
  • Set the duration within which all threads have to be run
  • Number of times to execute each thread (each thread can repeat a certain number of times)
  • Set the schedule to start the thread

Elements like Listeners (which we cover later in this topic) can be added to a Test Plan or Thread Group. When they are added to a Test Plan, they are associated with all the Thread Groups in the Test Plan. When they are added to a Thread Group, they apply only to that Thread Group.

Samplers and Controllers can only be added to a Thread Group.

Samplers

In order to connect to the server, users create the requests through their browser. We use Samplers when we want to simulate this in JMeter. Users can choose the requests type/protocol of the feature being tested.

JMeter supports many types of requests such as HTTP request, FTP request, JDBC requests etc.

This topic discusses the 4 most popular samplers in JMeter. JMeter_Samplers_Tutorial

HTTP Samplers

This is used when you want to test your web application performance using the HTTP protocol. It allows you to configure your samplers as HTTP request.

  1. JMeter creates HTTP request to server
  2. Server respond back to JMeter with data
  3. JMeter collects the data to analyze and generates reportJMeter_Tutorial_HTTP_Samplers_Workflow

FTP Samplers

Some websites like web hosting providers, file download sites (Ex. download.com) may require the use of an FTP server to download and upload files. In such projects you may need to verify the performance of the FTP server. You can simulate the user upload and download of files from FTP server by creating the FTP samplers request in JMeter.JMeter_Tutorial_FTP_Samplers_Workflow

In order to use the FTP Samplers, JMeter will require you to enter some important parameters as below

Attribute Description
Server Name Name or IP Address of the FTP server under test
Port Number The FTP port to use. Default port is 21
Remote File The File will be downloaded from FTP server
Local File The Destination folder for download (Where is the file downloaded to)
Get/Put File is to be downloaded or uploaded
Account User \ Password to login the FTP server

JDBC Samplers

Let us assume that you want to simulate 1,000 users connecting to your database server. Testing this scenario would not be feasible manually. JMeter’s JDBC Samplers are used in such situations, where you need to test your database’s performance.

It allows you to execute a query in the database and see how the database performs.JMeter_Tutorial_JDBC_Samplers_Workflow

In Database server testing, JMeter does as following

  1. Creates JDBC requests to database server under test. JDBC request is a SQL query statement.
  2. Receive the response from server
  3. Analyze the result, which can be visualized in a graph

When using JDBC Samplers there are some important parameters details that you need to provide.

Attribute Description
Database URL IP address of Database server under test
JDBC Driver The Java Library which JMeter can use
SQL Query SQL query to be executed
Account User \ Password to login to the Database server

SMTP Samplers

Most web applications use email notifications during user registration and transaction confirmation. Some web applications like Facebook, Amazon, Flipkart send out notifications quite frequently.

If there is significant use of email notification in your application, you may want to test the performance of your email server.

In order to test your email server, you will need to use the SMTP Samplers. SMTP Sampler can send email messages using SMTP protocol.

The screenshot shows the parameters that can be configured in an SMTP Sampler.JMeter_SMTP_Samplers

Details of parameters required by the SMTP sampler

Parameter Description
Name Descriptive name of SMTP Sampler
Server Setting Information of mail server such as address, port
Mail Setting Sender address, Receiver address
Auth Setting Username & Password
Security Settings Security protocol to be used, if required
Message setting Subject and email contents

Processor

There are two types of processors in JMeter, Pre Processor and Post Processor.Processors_Tutorial_JMeter

Pre-Processors in JMeter

These are used to customize the Samplers functionality.

Example: You want to each thread to use a specific username and password, this could be done using a User Parameter pre-processor. There are several other Pre Processors like HTML Link Parser (which can extract a hyperlink from the response), HTTP URL Re-writing Modifier etc

Post-Processor in JMeter

Post Processors are used to process the response from the server. These are executed before Assertions (which we will discuss later).

Example: If you would like to search for the text “Out of stock” in the response, you can use the Regular Expression Extractor. Some other Post Processors that are available in JMeter are : CSS/JQuery Extractor, XPath Extractor, JDBC PostProcessor, Result Status Action Handler etc.

Processors are applied to the output of all the Samplers that are at the same level as the Post Processor. If you want to apply the Processor to a specific Sampler, you should add it as a child of that Sampler.

We will discuss more processor in detail in the tutorial on Processors in JMeter.

Listeners

Quick Recap: So far, we have seen how Samplers are used to create and send a request to the server to execute a performance test. Processors can be used to modify the request or the response.

After creating and sending the request to server, JMeter receives the results returned from the server. Listeners help users to access the server response and analyze the test results.

The test data can be presented in several formats such as Graph, Table, Tree View, Logs files etc. JMeter provides several listeners in order to capture and read the data in graphical, textual and tabular formats, among other.

With the graphical view, user can analyze the data easily. However if you need to view the response data you can use Listeners that display the data in a tree or tabular format.JMeter_Listeners

Some of the commonly used Listeners in JMeter are explained below.

Graph Results Listener

This Graph Results Listener in JMeter is used to visualize the results of the test as a graph. It also has the option to write the results to a file. This can be done by specifying a file name in Filename field.

JMeter_Tutorial_Graph_Results_Listener

View Results in Table Listener

The View Results in Table Listener displays the results in a tabular format.JMeter_Tutorial_View_Results_In_Table_Listener

View Results Tree Listener

The View Results Tree Listener is used to view the output data in a tree structure. This Listener also allows you to view the data from the response in Response Data tab.JMeter_Tutorial_View_Results_Tree_Listener

Simple Data Writer Listener

Simple Data Writer Listener is used to save the test data directly to a file without displaying it visually.JMeter_Tutorial_Simple_Data_Writer_Listener

Important points to note about Listeners

  • The data collected by all the Listener is the same. The only difference between the Listener is in the way the information is displayed.
  • Listeners can be added at any level. The Listener will capture the data for the level at which it was added and the levels below it.
  • You can add different Listener for each ThreadGroup in which case it will only capture data for that ThreadGroup
  • Listener added to the TestPlan will capture data for the complete TestPlan and all ThreadGroups in it.
  • You can configure the data to be captured by clicking on the Configure button on the Listener.
  • You can configure the Listener to capture the data in a file as a CSV or JTL by providing the filename and path for the file where the data is to be logged. This feature is available in every Listener.

Assertions

Assertions are statements that verify the test results as either positive or negative. Assertions in JMeter can be applied to many elements such as Test Plan, Thread Group or Samplers.JMeter_Assertions_Tutorial

Example: You have deployed your application on a server and want to test if your application performs without any errors, under heavy usage. Only checking the throughput, response time etc may not be sufficient. You decide to check for the HTTP response code “200” which shows that the status is ok. You can use JMeter’s Response Assertion to help you verify the status. If the response code contains the text ”200” the test passes, otherwise the test fails.JMeter_Tutorial_Response_Assertion

JMeter has several types of assertions like Compare Assertion, Duration Assertion, Size Assertion, HTML Assertion etc.

We will discuss Assertions in detail in the JMeter Assertions tutorial.

Config Elements

Many desktop applications have a Setting menu option, which allows the user to configure or change some parameters of the application. Config Elements in JMeter are similar in nature.

Config Elements in JMeter allow the user to change the request they create. They can be used to add and modify the parameter values of the request as required.

There are several Config Elements in JMeter, some of the common ones are: HTTP Request Default, HTTP Cookie Manager, CSV Data Set Config, Login Config Element etcJMeter_Config_Elements

HTTP Request Defaults

HTTP Request Default is the key element of JMeter. Most testing scenario uses it.

The main purpose of using HTTP Request Defaults is to avoid data duplication and make the test plan more maintainable.

When you use the HTTP Request Defaults Config Element, you can set it up with all the parameters that will be common across all the HTTP Requests. You can enter details like the server name or IP, path, port number etc.JMeter_Tutorial_Config_Element_HTTP_Request_Defaults

Example: Let us assume that you need to create a Test Plan with 20 HTTP Request Samplers to the same application but different paths to test different scenarios. By using HTTP Request Defaults Config Element, you only need to enter the common details once in the Config Element and you can skip them in the Sampler.

You will not need to enter the same details 20 time again in the samplers, all Samplers will inherit the HTTP Request Defaults properties.

HTTP Cookie Manager

Some websites create a user specific cookie once a user logs in. The website may force the user to login again, if this cookie is not found. Browsers such as Chrome or Firefox then store the user’s information as cookies.

Example: If your application uses cookies to track users, you can use the Config Element – HTTP Cookie Manager which mimics this feature.

As shown in the figure below, you can use HTTP Cookie Manager to create a cookie with the values that you need for your test. After that, HTTP Cookie Manager saves those cookies and uses it for future requests.JMeter_HTTP_Cookie_Manager

CSV Data Set Config

When you test a website, one of the common operations is to login to the website. There are two parameters you may need username & password. What should you do if you want to login with different accounts?

JMeter offers the CSV Data Set Config that is used to parse data from CSV file and store them into variables.JMeter_Tutorial_CSV_Data_Set-Config

Field Name Description
Filename Text file which contains user and password
Variable name the equivalent to a field in a text file
Delimiter Normally the comma

Login Config Element

Login Config Element can be used to set up username and password for later use by Samplers. It is often used in test scenarios to simulate a user visiting a website and logging in with his username and password.JMeter_Login_Config_Element

Logic Controllers

There are two types of controllers in JMeter, Samplers and Logic Controllers.

In the Samplers section, we discussed about how JMeter creates a request to the server. The question is – If want to control those requests based on a logic such as setting the schedule to send that request, determine which request to be sent… etc. what should you do?

JMeter provide you with the element to do it. It is the Logic Controller.

JMeter offer you many types of Logic Controllers. You can use appropriate Controller based on your specific requirement.

Some common Logic Controllers are: Recording Controller, Simple Controller, Loop Controller, Random Controller, Module Controller etc.JMeter_Logic_Controllers_Tutorial

We will discuss Logic Controllers in detail in our tutorial on Logic Controllers in JMeter.

Timers

In the real world, when a user visits a website on their browser, he/she must wait a certain amount of time until the website is completely loaded in the web browser before they can perform the next action.JMeter_Timers

To simulate this scenario, JMeter creates many HTTP requests to the server. By default, those requests are sent to server continuously without any delay between them. It may cause the server under test to overload and this may not portray the results seen in real life.

Therefore, you need to create a time delay between each request. JMeter offers elements called the Timer elements that you can use in such situations.

The purpose of Timer elements is to pause a JMeter Thread representing a virtual user, for a certain amount of time.

We will delve in depth into Timers in the JMeter Timers tutorial.

Order of execution / processing of Elements in JMeter

Elements in JMeter are processed in the order shown below:

  • Configuration Elements
  • Pre-Processors
  • Timers
  • Sampler
  • Post-Processors
  • Assertions
  • Listeners

JMeter processes Samplers and Logic Controllers in the sequence that they appear in the Test Plan. Pre Processors, Post Processors, Assertions and Timers are only processed if they are associated with a Sampler.

In the next topic we will start with the practical exercises, beginning with getting to know the JMeter GUI application interface.