How to Feed JMeter from a CSV File
JMeter has to be one of my favorite tools. It is probably best known for performing website stress and load testing, but it is very useful in other capacities as well. At the shop, I needed to isolate a core content server API client, so I created a JMeter plugin which acted as the test harness, and I was able to stress and trace the client/CMS interface without having to instrument any of the application source code.
When I migrated this website from my homegrown CMS to Drupal, I needed a means to perform a quick smoke test to make sure all the URLs were working properly. In the past, the majority of the test plans I've used had a relatively small set of target web resources, and they were included as explicit samplers in the JMeter test plan. However, for this exercise I did not want to create well over a 100 explicit sampler requests and preferred to drive the tests from a data file instead. I wasn't having much luck finding an exact example, so I decided to figure it out from the JMeter docs instead. Hopefully, this post will help if you have a similar use case for this testing scope.
Functional Requirements
Perform a series of HTTP GET requests for a web property using a list of virtual paths contained inside of a text/CSV file.
Prerequisites and Assumptions
- Working JDK installation (I'm using JDK 6 on Win 7 64-bit)
- Working JMeter installation (I'm using version 2.5.1 r1177103 at the time of this post)
- Working knowledge of JMeter basic operations: starting, stopping, building and executing upon a test plan
- A text file containing the virtual paths of the URLs under test
Basic Steps
Establish a Working Directory
It is a good idea to have both your data file and .jmx file in the same directory to avoid confusion. For the purpose of this exercise, I performed and executed from c:\web\tests.
Create a Data File Containing Virtual Paths
This is a simple text file with one line per virtual path. It has a .csv file extension but technically it contains only one column. Obviously, this could contain other columns separated by a comma or other desired delimiter. The following is an example of the contents. Note each is a relative path and excludes the host and domain name as this is supplied from the HTTP Request Defaults Config Element.
My text file is named: "urls.csv"
/resource-1
/webpath/resource-2
/webpath/resource-3
/webpath/subpath/resource-4
Create a Test Plan
Step 1
- Start JMeter
- Name test plan: (I used 'HTTP Get from CSV')
- Save test plan in working directory: (I used 'http-get-from-csv.jmx')
Step 2 - Add Thread Group
- {right-click} [HTTP Get from CSV] > Add > Thread (Users) > Thread Group
- Set "Name:" to: Users (optional)
Step 3 - Add While Controller
- {right-click} [Users] > Add > Logic Controller > While Controller
- Leave original "Name"
Step 4 -Add HTTP Request
- {right-click} [While Controller] > Add > Sampler > HTTP Request
- Leave original "Name:"
- Set "Server Name or IP:" to: target website host and domain
- Change "Port Number:" if target website listens to non-standard HTTP port
- Set "Implementation:" to: Java
- Set "Method:" to: GET (if not set already)
- Set "Path:" to: ${URL}
Step 5 - Add CSV Data Set Config
- {right-click} [HTTP Request] > Add > Config Element > CSV Data Set Config
- Set "Name:" to: urls.csv (not mandatory)
- Set "Filename:" to: urls.csv (must match data file name)
- Set "Variable Names (comma-delimited):" to URL
- Set "Recycle on EOF ?:" to: False
- Set "Stop thread of EOF ?:" to True
Step 6 -Add a Timer
- {right-click} [HTTP Request] > Add > Timer > Constant Timer
- Set "Thread Delay (in milliseconds):" to: 1000 (for one second)
Add a Listener
- {right-click} [Users] > Add > Listener > View Results In Tree
This is what you'll be watching during the test plan run.
You can also add a "View Results in Table" as an alternative and it will show timing information during the test run.
The following infographic highlights the configuration elements for this test plan.

Once the test plan is complete, click on one of the listeners and select Run > Start and monitor the progress.
Cheers
