0
votes

I have a directory with CSV files. each file contains a list of GET requests I'd like to make with JMeter. What I'd like to do is read all the files in a directory, and then loop through each CSV to send the requests in JMeter. The number of files isn't consistent so I don't want to hard code the file names into CSV samplers.

So in effect I'd like to read all the files in the directory and store the files in an array variable. The loop through the array and send the CSV file to the CSV sampler which will in turn read the CSV file and pass the content to an HTTP Request sampler to send the GET requests.

I created a beanshell script to read the files in the directory and store them in an array, but when I try to pass this to the CSV config element, I get errors stating the variable doesn't exist.

I've tried another beanshell script to read the file and pass the lines to an HTTP request Sampler as a variable, but the issue was, it would store all the file contents in memory per thread.

I'd like to know the best approach to read the files, send the requests and use the response data to generate reports

1

1 Answers

0
votes
  1. You will not be able to populate CSV Data Set config using Beanshell as CSV Data Set Config is a Configuration Element and according to Execution Order user manual chapter Configuration Elements are executed before anything else.
  2. Since JMeter 3.1 you should not be using Beanshell, it is recommended to switch to JSR223 Elements and Groovy language

I would recommend going for Directory Listing Config plugin, it scans the provided folder (in your case with CSV files) and stores the found paths to files into a JMeter variable

JMeter Directory Listing Config

So you can use the Directory Listing Config in combination with __StringFromFile() or __CSVRead() functions and that should be more or less good way of implementing your requirements.