SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

JMeter - CSV Data Set Config Usage

CSV Data Set Config is one of the configuration element of Apache JMeter software load testing tool. CSV Data Set Config allows you to read variable values from csv file and then you can use those values in samples of your software load test plan as per your requirement. Here we will see, How to add CSV Data Set Config in your software load test plan and how to read data from csv file. Let's learn with example.

Add CSV Data Set Config In Software Load Test Plan
You can add CSV Data Set Config under thread group, controller or request as per your requirement. But please note one thing here, It will be processed before any samplers in the current scope regardless of its position. So when you run test, First it will process CSV Data Set Config and then it will execute samplers.

Have you Read about Synchronizing Timer?

Let's add CSV Data Set Config under thread group of your software load test plan. To do so,
  • Right click on Thread Group,
  • Select Add -> Config Element -> CSV Data Set Config as shown in bellow image.


It will add CSV Data Set Config under Thread Group.

Parameters Of CSV Data Set Config
CSV Data Set Config has many different parameters as shown in bellow image to configure it as per your requirement. Let me explain them.

  • Filename : In this field, You can set CSV data file name and it's path. Example : E:\Test.csv
  • File Encoding : This field will be used when encoding is used to read the file.
  • Variable Names : Variable names list with comma-delimited to store values which are read from csv file. Example : X,Y,Z
  • Delimiter : Delimiter to use to split data during reading it from file. Use comma(,) for comma-delimited file and \t for tab delimited file.
  • Allow quoted data? : If you wants to read double quoted(") data from file then set it to true. Example : "Y2".
  • Recycle on EOF? : Set it to true if you wants to read data from beginning of file when reaching on end of file. Default it will be true.
  • Stop thread on EOF? : Set it true if you wants to stop thread on end of file if Recycle on EOF? = false.
  • Sharing mode : If select All threads then it will share file between all threads. If set current thread group then each file will be opened once per each thread group. If set current thread then each file will be opened separately for each thread.
Using CSV Data Set Config In Software Load Test
Scenario : I wants to read data(from 3 columns comma-delimited) from csv file and print in view result in tree using Debug.

I have created very simple load test plan to explain how to use CSV Data Set Config in software load test plan to read data from csv file.

I have added CSV Data Set Config under Thread Group as shown in bellow image.


Test.csv file has data like bellow. You can download it from THIS PAGE.


You can see that we have 3 data columns in csv file so we have used 3 variables(X,Y,Z) in CSV Data Set Config.

Thread group configuration is as bellow. Loop count is 15 iterations.


I have used Debug Sampler to see all 3 variable's values on each thread iteration.


Now if you will run above test, output of 1st debug sampler will looks like bellow.




In 1st debug sampler's result, You can see that CSV file's first row data is printed. Same way, 2nd row's data will be printed in result of 2nd debug sampler's result and so on.

If you wants to use variable's data anywhere in your software load test plan then you can use it this way -> put ${X} To use X variable's value

As you know, We have only 5 rows data in csv file and loop count in thread group is 15. So 6th debug sampler will print 1st row's data again as we have set Recycle on EOF? = true in CSV Data Set Config. In this case, It will start reading data from beginning of file once reach on end of file.


This way, You can use CSV Data Set Config in your software load test plan to read data from csv file.

No comments:

Post a Comment