Data Driven Testing in JMeter

Reading Time: 5 minutes

Hi folks,

Initially, In this blog we will go through the data driven testing concept, then we will briefly see the step by step process of implementing the JMeter test script using data from external sources.

Data driven testing?

Data-driven testing is one of the most important mechanisms to determine the stability of the application. 

Mostly, when an application is tested by a tester manually then different scenarios are performed against different test data. The test data is used for manual testing is usually stored in some files like excel files, CSV files, and text files.

Likewise, for running automated tests against a large set of test data you can have different repositories/databases/files to maintain the test data. A data-driven testing framework is a technique in which you keep input test data separate from the actual test script.

Data driven load testing?

Let’s assume You have the task to load test the login functionality of the application under test. Since it is a load test, you can not test it with a single login. In this case, you need to test it with multiple test data and hence you need to use the concept of data-driven testing.

Let’s suppose an example: There is a website and you need to do load testing on the login page of the website so that you can know how much a load of user requests it can perform effectively.  Suppose a scenario of 1000 users, for that you need 1000 usernames and 1000 passwords and similarly other details. You need to pass these values 1000 times to make this load on the login page. So in JMeter, there should be some mechanism where data driving should happen.

Here comes data-driven testing in the picture and In JMeter, we use an external source and put all data there and then link the external source to JMeter script. That’s how you can achieve this task.

Implementation Steps :

STEP 1 :

Put all the data in a CSV file.

In my case, I am using a dummy website to load test that’s why I have taken a single dummy login credential for demonstration but you can use as many as you want.

STEP 2 :

Open JMeter –> create new Test Plan –> right click Test Plan –> Add –> Config Elements –> CSV Data Set Config

STEP 3 :

Configure JMeter to read CSV files by providing Filename (path), Variable Names and other fields if required according to your usage.

Fields under CSV dataset config:

a)Filename: This refers to the path to the CSV file which contains the test data.

b)File Encoding: The encoding technique by which you want to read the CSV file eg: UTF-8.

c)Variable Names: List your variable names(comma separated) to match the columns in the CSV file. You can keep this field empty if you want to use the first line of the CSV file as the variable name.

d)Ignore First Line: Set this field to True if you want to ignore the first line of the CSV file, else take the default value – False. It is used only if the variable names are not empty.

e)Delimiter: ‘,’ by default, you can set anything else too.

f)Allow Quoted Data: Set this field to True if you have double quotes in CSV columns, else take the default value -False.

g)Recycle on EOF: Set this field to True if you want JMeter to restart from the beginning when the End Of File is reached, else take the default value -False.

h)Stop Thread on EOF: Set this field to True if you want to stop the current thread if EOF is reached; else take the default value -False.

9)Sharing Mode: It selects threads that share the same file pointer.

In my case, I am giving the path of my CSV file in Filename and providing variable names (email, password) because I have only two fields on my login page but you can provide variable names according to your usage and I am leaving the rest fields as it is but you change it according to your need and use.

STEP 4 :

Add a Thread Group : right click Test Plan –> Add –> Thread (Users) –> Thread Group

STEP 5 :

Add an HTTP Request sampler : right click Thread Group –> Add –> Sampler –> HTTP Request

After adding an HTTP Request sampler you need to configure it according to your web address.

In my case I am using a dummy website (https://blazedemo.com/login) so “http” will be my protocol, “blazedemo.com” will be my Server Name, “/login” will be Path for the login page and set it as POST.

STEP 6 :

Add variables : click on Parameters –> click on Add

You need to add variables that you defined at the time of CSV Data Set Config by clicking “Add”.

In my case, i added two variables because my login page consists of two fields but you can add according to your need and make sure you have declared those values in CSV Data Set Config.

Always use ${your_variable} to specify your variable.

STEP 7 :

Add Listener to view result : right click on Thread Group –> Add –> Listener –> View Results Tree

STEP 8 :

Save your test and Run the script

Bingo !! you have successfully run your data-driven testing in JMeter.

STEP 9 :

Verify your result response with your CSV data

As you can see in the request body we have got the same data(email & password) that we provided in our CSV file.

That’s all about this blog and to explore more you can click here to reach out more related blogs.

References

https://jmeter.apache.org/usermanual/index.html

Scala Future

Written by 

Sujeet is a Software Intern at Knoldus Software. Knoldus does niche Reactive and Big Data product development on Scala, Spark, and Functional Java. He is always charged up for new things & learning. He is dedicated to his work and believes in quality output. On a personal front, he loves to play volleyball and is a big foodie.

Leave a Reply