Sampler in JMeter with Examples

In this JMeter Tutorial, you will learn Samplers in JMeter. We know that in real time when we send request to the server, we get response from the server. Same thing is done by JMeter using Sampler which is used to send different types of request to the server and in return get the response from the server so we can say that Sampler are actual request which is sent to the server through JMeter. In JMeter, Sampler is added to the thread group.

First, we need to add thread group inside Test plan. Now a new window will open with the title Thread group where we can rename it and create scenarios. It can be done by right-clicking on Test Plan. Then select add. Then Select Thread Group… Navigation is as Shown in the following screenshot.

Sampler in JMeter

After adding new thread, new window appears as shown in the screenshot below. We can see that the name of thread group up is My Thread group which is the name given to the Thread. We can give any name.

There are many other things which are defined in Thread Group to create scenario but we will discuss it later because we have to focus on Sampler now. It is just that we have to create thread group for.

creating Sampler because we have to add Sampler inside Thread Group. That is why we have to understand how to create thread group.

Sampler in JMeter 2

Now after Thread Group is created, we will focus on how to Create Sampler in JMeter.For adding Sampler, we simply need to right-click on thread group which is created under test plan and then we need to select Add, then we need to select Sampler and from there we can see number of Samplers available which we can select depending on our requirement because each simpler serves a specific purpose. We can see all the samplers in the screenshot which is given below.

Sampler in JMeter 3

We can clearly see that there is large number of samplers available in JMeter which we can see in the screenshot given above. Each sample serves specific purpose. We do not use all the samplers frequently. 

We use some of them frequently. Some of the most commonly used samplers as are as given below.

Sampler is very important part in performance testing because it acts like a request to server and gets the response back to the client.

So we had to understand the concept very clear. Let us see them one by one.

HTTP request

As the name itself is telling, it is used to send HTTP and Https requests to the web server whenever we will be configuring HTTP request we can put the name of HTTP request as per our convenience and relevance and we need to enter Server Name or IP in the relevant field and also need to add path to it. Path is extended URL which is a added after base URL. It is simplest sampler which is used in JMeter.

We need to specify protocol as well. We can see Protocol section in HTTP Request window which we can see in the screenshot below. We can also see one other field which is Server Name or IP. Here we can enter IP of the server where we want to send the request. We can also enter Server Name which will solve the same purpose of sending the request. We need to ensure that there is correct data filled in this field. Screenshot for this sampler is as given below.

Sampler in JMeter - HTTP Request

FTP request

Now we should understand that it is little different than HTTP Request. FTP request Sampler in JMeter makes it capable to send FTP file for downloading and uploading. We can say that FTP request Sampler help us to send download or upload request to the FTP server.

It is important to understand some of the things while configuring FTP request. While configuring FTP request we need to give Domain Name or Server Name or IP address of FTP server then we need to give filename which we need to retrieve. Now there is option to download a file or upload a file we need to select the option and we also need to provide username or password if required by FTP account user. We can see FTP Request window in the screenshot given below where we can see various options to configure FTP Request.

Sampler in JMeter - FTP Request

JDBC request

That is not so commonly in JMeter, but it can be used for database testing. We can change jdbc request in the form of SQL Query to a database and get the response. We can write some some query statements to perform some operation on the database and get the response from the database server. We can perform various types of operations like we can add, delete or update the record in the database using JDBC request Sampler. We can change jdbc request using this Sampler. We can see JDBC request window of JMeter in the screenshot given below where we have option to execute SQL statements on a particular database which we need to connect through JMeter and get the response.

Sampler in JMeter - JDBC Request

SMTP Sampler

It is also not so commonly you JMeter but to have knowledge of it we should understand that it is used to test mail server. JMeter send email message using SMTP or SMTPS protocol to the mail server in order to test the mail server. There are some parameters that need to be configured while sending mail. Even when we send mail through Microsoft Outlook, some configuration for sending emails has to be done. Same configuration needs to be done in JMeter also for sending mail. We can see the same in the screenshot below available for SMTP sampler in JMeter where we can see various parameters fields with us to be configured for sending mail through JMeter.

Sampler in JMeter - SMTP Sampler

These are some of the samplers which are most frequently used in JMeter. There are other samplers as well which we use depending on our requirement and which serves a specific purposes but are not so frequently used. Only thing we need to focus is that we have to understand what each sampler is used for.