Insights from Our Experts

Blog image

Parameterization using JMeter in simple 7 steps

Author Image

Shinoj Surendran,QA Lead

Parameterization using JMeter in simple 7 steps

 

It's a pain entering hardcoded values every time as input parameters while performing a function or API testing. If we could have all the parameters at one place to fetch from, maybe a file, table or an excel DB well that would make a tester's life easier for sure. Parameterization makes it happen, it is a test strategy that automates a test case and runs it multiple times with different input values. This strategy allows users to read data from a file or database as mentioned earlier rather than using hard-coded values.

 

JMeter is a load testing tool for analyzing and measuring the performance of various web services and it supports Parameterization.

 

To show you how Parameterization works with JMeter, we will be using a REST API and running a case on “ExchangeRate-API” that will return the exchange currency rates.

 

Step-1 Add the test plan

 

Create a test plan and define what to test and how you want to test it.

 

Fig-1-1


 

Step-2 Create the Parameterization table in .csv format

 

From the “ExchangeRate-API” following parameters will be used to test the exchange rates from one currency to another.

 

  • ‘YOUR_KEY’- is the unique key parameter for each registered user.

  • ‘from’ - is the parameter for currency code which is to be converted from.

  • ‘to’ - is the parameter for currency code which is to be converted to.

  •  And Save the file ("exchanegerates.csv") in your system.

Fig 2-1

Step-3 Add a thread group and set priorities

 

Select Test Plan >  Add > Threads(Users) > Thread Group

 

Set the thread properties as follows :

 

Number of Threads(users): Enter the number of rows in the .csv file

Ramp-up period(seconds): Mention in seconds how long it will take  to start execution of all the threads

Loop Count: Specify the number of times to execute the test. We are entering “5” since our csv file contains 5 rows of parameters.

Fig 3-1

.

 

Step 4: Configuring CSV Data Set

Let’s do the configuration fields.

  • File name: Enter the directory path of  the csv file.

  • File encoding: The encoding to be used to read the file

  • Variable Names(comma-delimited): It's the list of variable names, if this field is empty, the first line of the file is read and interpreted as the list of column names.

  • Delimiter: Delimiter to be used to split the records in the file. 

  • Allow quoted data?:  This checks if the CSV file should allow values to be quoted. By default, it is set as “False”.

  • Recycle on EOF: This checks if File should be re-read from the beginning on reaching EOF. By default, it is set as “True”.

  • Stop thread on EOF: This checks if the thread should be stopped on EOF if Recycle is false. By default, it is set as “False”.

  • Sharing mode: This checks if the thread should be shared. By default it is set as “All threads”.

Fig 4-1

Step 5: Add an HTTP Request sampler and set web server, path and parameters.

It sounds a lot but it’s simple!

 

Select Thread Group > Add > Sampler > HTTP Request

 

Fig 5-1

 

The following are the steps to set the IP, Path, Parameters, etc. for HTTP Request.

  • Set Web Server details

Server Name or IP: v3.exchangerate-api.com/ (From the ‘ExchangeRate-API')

  • Set HTTP Request details

Implementation : HttpClient4 

Protocol [http]: https   

Method : GET

Path : pair/YOUR_KEY/from/to

(From the ‘ExchangeRate-API’)

Variables are referenced in Jmeter as follows:-

${variable_name}

Change the path as  pair/${YOUR_KEY}/${from}/${to}  according to our csv file column titles.

  • Set Parameters

Set the parameters as per our csv file. Name column consists of all the column titles and the value column consists of respective variable names in ${}format.

 

Step 6: Add Listeners (View results in table, view results in tree)

Select Thread Group > Add > Listener > View Results in Table. Same as for ‘View Results in Tree’.

 

Step 7: Run and validate the test

 

Save  (Ctrl+S) and Run the test (Ctrl+R). Observe the Listeners

The View Result in Table listener displays all information about each sample in the form of a table. The table shows time-related data for each sample, the payload data, the thread number and the sample execution result. 

Fig 7-1

The View Results Tree listener will show samples that the JMeter samplers generate. For each HTTP Request sampler, the View Results Tree listener provides the request parameters, response parameters, and the response data will be displayed under the corresponding tabs such as sampler result, request, and response data.

 

The Sampler result tab contains the response code, headers, cookies and information about time etc.

 

Fig 7-2

 

The Request tab contains information about headers that the JMeter script added, the URL, the HTTP method and cookie information.

 

  Fig 7-3

 

The Response data tab contains the response body of the sample.

 

 

Fig 7-4

 

The instructional read was created to give you insights on how to improve your software testing capabilities, at Sayone we build web and mobile applications with watch-making precision. Drop in a word and our industry experts will reach out to you.

 

I Need

Help for