Using Apache JMeter
First question: I was able to read one single file (containing all the data) from a directory and use its data.
However now the requirement is to have a separate file for each data point, that means I will have to put many data files in a directory and then read the files off that directory. I have a set of data files, but I do not know how to read each of the files in a loop and send it to JMeter.
Second Question: the data we are talking about here is a JSON msg, and it's indented and multi-line, how to read a multi-line file into a single input variable? Again, I had no problem when the JSON msg is a single line.
FileServer; //Open the file FileInputStream fstream = new FileInputStream("C://QC//qa//Testlink//Jmeter//Expected//test.xml"); //Get the object of DataInputStream DataInputStream instream = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(instream));
Use Beanshell Sampler to convert files list into a JMeter Variable:
Put the following code into the Sampler's "Script" area:
File folder = new File("/path/to/your/folder");
File[] files = folder.listFiles();
int counter = 1;
for (File file : files) {
vars.put("file_" + counter, file.getAbsolutePath());
counter++;
}
It will result into variables set like:
file_1=/path/to/your/folder/file1.txt file_2=/path/to/your/folder/file2.txt etc.
Add ForEach Controller after Beanshell Sampler and configure it as follows:
file
0
current_file
Add "_" before number
${__FileToString(${current_file},,)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With