• info@helpingtesters.com
  • helpingtesters

What are JMeter Samplers and Types

September 10, 2017 JMeter Tutorial
JMeter Samplers, JMeter Samplers, Samplers in JMeter, Sampler in JMeter

In the previous blog, we studied about different ways in which a request can be sent to hit the server. Now, we will see the different type of requests that can be created in JMeter to serve the purpose of kind of scenario that one is trying to simulate. JMeter Samplers have all the information regarding a particular request. The server that it is going to hit, the port, the protocol used, the body of a request, variables and their values. It is the request that will ultimately hit the server and get a response back. 

→Complete list of JMeter Tutorial Series

Below is the process to add JMeter Samplers:

Do right click on Test Plan > Add > Threads > Thread Group

Do right click on Thread group > Add > Sampler > Select Any Sampler

 

Some of the popular JMeter Samplers are as below

  • HTTP Request
  • Java Request
  • JDBC Connection request
  • FTP Request

⇒ HTTP Request JMeter Samplers

An HTTP Request JMeter Samplers is used to send the request to the server. One can send HTTP/HTTPS type of requests through it.

In order to add this sampler right click on Test Plan > Add > Threads > Thread group > Add >   Sampler > HTTP Request

 

  • Name: Any logical name in order to distinguish your request.
  • Protocol: It mentions the protocol used for example HTTP or HTTPS. A https protocol is used for
  • Server Name: This is the domain name of the server
  • Method: Any of the methods such as GET, PUT, POST, DELETE etc may be selected from the drop down
  • Path: This is the path of the resource. For example “/wiki/Cheese”.
  • Parameters: Any parameters that are required to be passed will be added in this section.
  • Body Data: This comes into picture if any JSON, XML etc needs to be passed in the request. That is added in Body Data.

 

⇒ Java Request JMeter Samplers

This JMeter Samplers helps to generate multiple threads, control the input parameters and collection of data.

In order to add this sampler right click on Test Plan > Add > Threads > Thread group > Add >   Sampler > Java Request

Once JMeter Samplers is added, below fields are seen:

Name: This is any descriptive name for the sampler

Class name: This has 2 options

  • apache.jmeter.protocol.java.test.JavaTest
  • apache.jmeter.protocol.java.test.SleepTest

These are Java classes that can be implemented using JMeter.

 

Send Parameters With The Request

Below are the parameters that are displayed in the request by default. 

  • Sleep_Time: Time to wait (ms)
  • Sleep_mask: This adds the randomness based on below formula: totalSleepTime = SleepTime + (System.currentTimeMillis() % SleepMask)
  • Status: “Ok” status will mark status to be success
  • Label: It is the meaningful name, in case it is provided then it will override the name given in “Name” field.
  • Response Code: This gives the response code of sample result. Set as “200”  for the successful response.
  • Response Message: This gives the response message of sample result. Set as “OK” for the successful response.

Values in other fields are set as default.        

 

⇒ JDBC Connection Request JMeter Samplers

For sending the query to the database in the test runs – JDBC Connection Request JMeter Samplers are used. It helps to query the database with simple or complex queries and store result set. Values from the database can be used anywhere using the variable anywhere in the test run.

Firstly, one needs to add the configuration details by adding below component:

Thread Group  > Add > Config Element > JDBC Connection Configuration

Once this element is added, below fields are seen:

Name: Any logical name can be provided to distinguish this sampler

Variable Name: This is the name of a variable that connection will be using.

Max Number of Connections: This is by default set to 10. Usually, set to 0 this means that each thread will have a single connection and no connection will be shared between threads.

Max Wait: This is maximum timeout period. The error is thrown when this timeout period is exceeded.

Values in other fields can be set as default. Populate the data in fields as below:

Database URL: Connection string of database. For example JDBC: MySQL://host[:port]/dbname

JDBC Driver class: Name of driver class. For example com.mysql.jdbc.Driver

Username:  Name of user

Password:  Valid password

After adding the config element for JDBC Connection one can add the query in the sampler as below:

In order to add this sampler right click on Test Plan > Add > Threads > Thread  group > Add >   Sampler > JDBC Request

 

Any query returning the result set can be used in “Query” section.

From the drop down – > “Query Type”, multiple types of queries like Select, Update, Commit, Rollback etc can be selected.

 

⇒ FTP Request JMeter Samplers

“FTP” is File Transfer Protocol. This protocol is responsible for transferring files between client and server location. FTP Request Sampler helps to upload or retrieve files from FTP server.

In order to add this sampler right click on Test Plan > Add > Threads > Thread group > Add >   Sampler > FTP Request

 

Name: Any logical name

Server Name or IP: Domain name or IP address of the FTP server

Remote File: Name of destination file

Local File: Name of File to be uploaded. Used when File needs to be uploaded

Local File Contents: Overrides contents of Local File

Get (RETR): To retrieve a file

Put (STOR): To upload a file

About the author

Ankita Dawar author

Ankita has worked on different types of testing like Manual, Automation, Performance testing.  She likes to learn about new tools in market that help to make testing easier and interesting. Testing is her passion due to versatile areas it offers.

Leave a Reply

Your email address will not be published.