{"id":2165,"date":"2021-12-01T14:49:23","date_gmt":"2021-12-01T14:49:23","guid":{"rendered":"https:\/\/loadfocus.com\/blog\/?p=2165"},"modified":"2023-09-03T14:10:06","modified_gmt":"2023-09-03T14:10:06","slug":"how-to-use-csv-data-set-to-configure-jmeter-tests","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/2021\/12\/how-to-use-csv-data-set-to-configure-jmeter-tests","title":{"rendered":"How to Use CSV Data Set to Configure JMeter Tests"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>\n<p class=\"lead\"><a href=\"https:\/\/jmeter.apache.org\/\" rel=\"noreferrer noopener nofollow\" target=\"_blank\">Apache JMeter<\/a> is a Java-based, open source testing tool, which can help you create and run functional and load tests for Websites, APIs (REST and SOAP) and other web services.<\/p>\n\n\n\n<p>In this example we are going to have a look on how to create and run a JMeter test using a <strong>CSV file<\/strong> for our data, and consume the data in our test from that CSV file.<\/p>\n\n\n\n<p>First, let&#8217;s open JMeter and create a new JMeter test script. <\/p>\n\n\n\n<p>Add a <strong>Thread Group<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"275\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-thread-group.jpeg\" alt=\"\" class=\"wp-image-2279\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-thread-group.jpeg 631w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-thread-group-600x261.jpeg 600w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/figure>\n\n\n\n<p>Inside the Thread Group add the following:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><br>CSV Data Set Config<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"606\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-data-set-config.jpeg\" alt=\"\" class=\"wp-image-2280\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-data-set-config.jpeg 693w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-data-set-config-686x600.jpeg 686w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-data-set-config-457x400.jpeg 457w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><br>HTTP Request<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"633\" height=\"476\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-http-request.jpeg\" alt=\"\" class=\"wp-image-2281\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-http-request.jpeg 633w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-http-request-532x400.jpeg 532w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">View Results Tree<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"542\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-view-results-tree.jpeg\" alt=\"\" class=\"wp-image-2282\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-view-results-tree.jpeg 686w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-view-results-tree-506x400.jpeg 506w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Configure the CSV Data Set Config<\/h2>\n\n\n\n<p>Why do we need a <strong>CSV Data Set Config<\/strong> config element?<\/p>\n\n\n\n<p>Because the <strong>CSV Data Set Config<\/strong> is used to read lines from a file, and split them into variables, and is exactly what we need to be able to generate this data-driven tests.<\/p>\n\n\n\n<p>Inside the <strong>CSV Data Set Config<\/strong> there are few fields you need to configure in order to run Apache JMeter tests and load the data for the test from a CSV file.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"777\" height=\"390\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-config.jpeg\" alt=\"\" class=\"wp-image-2283\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-config.jpeg 777w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-config-600x301.jpeg 600w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-csv-config-768x385.jpeg 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/figure>\n\n\n\n<p>The <strong>Filename<\/strong> is the property which defines the name of the file to be read and we can use relative paths with respect to the JMX test script. <\/p>\n\n\n\n<p>So to use a CSV file located in the same folder as the JMX file, simply add .\/ in front of the CSV filename: <strong><code>.\/file1.csv<\/code><\/strong><\/p>\n\n\n\n<p>In order to use the values extracted from the CSV file, we need to define the variable names, in our case is a list of users and passwords, so we&#8217;ll add user,password (names must be separated by the delimiter character).<\/p>\n\n\n\n<p>Note: <em>JMeter supports CSV header lines: if the variable name field empty, then the first line of the file is read and interpreted as the list of column names.<\/em><\/p>\n\n\n\n<p>Next step is to choose the delimiter, we found out that the easiest to use is the comma delimiter, so in our CSV file we&#8217;ll separate the key,value pairs with a comma as below:<\/p>\n\n\n\n<p><code>John1,password1<\/code><\/p>\n\n\n\n<p><code>John2,password2<\/code><\/p>\n\n\n\n<p><code>John3,password3<\/code><\/p>\n\n\n\n<p>More details on the CSV Data Set Config can be found in the <a href=\"https:\/\/jmeter.apache.org\/usermanual\/component_reference.html#CSV_Data_Set_Config\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">JMeter docs<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure the HTTP Request<\/h2>\n\n\n\n<p>Now, in the HTTP Request Sampler we are going to use the values extracted from the CSV file by appending the variable names at the end of the PATH for the GET request:<\/p>\n\n\n\n<p><code>https:\/\/example.com?${user}&amp;${password}<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1019\" height=\"407\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-using-csv-variables.jpeg\" alt=\"\" class=\"wp-image-2284\" srcset=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-using-csv-variables.jpeg 1019w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-using-csv-variables-800x320.jpeg 800w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-using-csv-variables-600x240.jpeg 600w, https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/jmeter-test-using-csv-variables-768x307.jpeg 768w\" sizes=\"auto, (max-width: 1019px) 100vw, 1019px\" \/><\/figure>\n\n\n\n<p>We are going to run the JMeter test script we&#8217;ve created and check in the View Results Tree listener that the values for the PATH field in each request are going to be updated with the values extracted from the CSV file used in the CSV Data Set Config.<\/p>\n\n\n\n<p>And we can see that the GET requests made have the following Paths:<\/p>\n\n\n\n<p><code>GET https:\/\/example.com?John1&amp;password1<\/code><\/p>\n\n\n\n<p><code>GET https:\/\/example.com?John2&amp;password2<\/code><\/p>\n\n\n\n<p><code>GET https:\/\/example.com?John3&amp;password3<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run JMeter Tests with CSV Data Files in the Cloud<\/h2>\n\n\n\n<p>Now that we have a JMeter JMX test script and a CSV file used by the JMX file to inject the data in the test, we can run this test in the cloud from multiple cloud locations with thousands of virtual concurrent users using the <a href=\"https:\/\/loadfocus.com\/jmeter-load-testing\">JMeter Cloud Load Testing Tool<\/a>.<\/p>\n\n\n\n<p>Just go to New JMeter Test page, and upload the <strong>JMX<\/strong> and <strong>CSV files<\/strong> and hit the <strong>Run Test<\/strong> button, and your test will automatically run in the cloud:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler\"><div class=\"wp-block-embed__wrapper\">\n<div style=\"width: 580px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2165-1\" width=\"580\" height=\"326\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/d2woeiihr4s5r6.cloudfront.net\/loadtesting\/video\/new-jmeter-test-original.mp4?_=1\" \/><a href=\"https:\/\/d2woeiihr4s5r6.cloudfront.net\/loadtesting\/video\/new-jmeter-test-original.mp4\">https:\/\/d2woeiihr4s5r6.cloudfront.net\/loadtesting\/video\/new-jmeter-test-original.mp4<\/a><\/video><\/div>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"has-text-align-center wp-block-heading\"><a href=\"https:\/\/loadfocus.com\/pricing\"><strong>START TESTING TODAY<\/strong><\/a><\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><em>Written by&nbsp;<a href=\"https:\/\/coursinator.com\/instructor\/bogdan-vazzolla\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"broken_link\">Bogdan&nbsp;Vazzolla<\/a>.<\/em><\/p>\n\n\n\n<p><em><a href=\"https:\/\/loadfocus.com\/\">LoadFocus<\/a>&nbsp;is a cloud testing platform,&nbsp;a&nbsp;<a href=\"https:\/\/loadfocus.com\/load-testing\" target=\"_blank\" rel=\"noreferrer noopener\">load and stress testing tool<\/a>&nbsp;which provides the infrastructure to run tests with thousands of concurrent users, from&nbsp;<a href=\"https:\/\/loadfocus.com\/locations\">multiple cloud locations<\/a>, in less than a few minutes, keep history of the results, compare different runs to inspect performance improvements or performance degradation.<\/em>&nbsp;<em>It also supports running&nbsp;<a href=\"https:\/\/loadfocus.com\/jmeter-load-testing\" target=\"_blank\" rel=\"noreferrer noopener\">JMeter load tests from the cloud<\/a><\/em>&nbsp;and&nbsp;<a href=\"https:\/\/loadfocus.com\/page-speed-monitoring\">monitoring and audit web and mobile performance<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 3<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>Apache JMeter is a Java-based, open source testing tool, which can help you create and run functional and load tests for Websites, APIs (REST and SOAP) and other web services. In this example we are going to have a look on how to create and run a JMeter test using a CSV file for our&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/2021\/12\/how-to-use-csv-data-set-to-configure-jmeter-tests\" class=\"more-link\" title=\"Read How to Use CSV Data Set to Configure JMeter Tests\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9,6,48],"tags":[369,368],"class_list":["post-2165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache-jmeter","category-load-testing","category-performance-testing","category-test-automation","tag-csv-data-set-jmeter-load-tests","tag-jmeter-csv-data-config"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/2165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/comments?post=2165"}],"version-history":[{"count":2,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/2165\/revisions"}],"predecessor-version":[{"id":2775,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/2165\/revisions\/2775"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media\/2289"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media?parent=2165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/categories?post=2165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/tags?post=2165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}