2
votes

I want My Jmeter to read multiple csv file from a location say c:\Jmeter\file.

Currently if i provide the specific csv file name in'Filename' under CSV data Set Config, the Jmeter recognizes the file ans execute my script.

I don't want to hard code the file name , i want the jmeter to read automatically from the location.

I have written BeenShell PreProcessor (since i couldn't find any simple solution) this program reads the list all csv files from location and stores them in variable. 'VcsvFilename'

import java.io.File;

    File folder = new File("C:\\Intel\\CsvFiles");
    File[] listOfFiles = folder.listFiles();
    String[] desiredNamesOfListOfFiles = new String[listOfFiles.length];
    String strFileName;
    int intCounter=0;
    String count;
    int idx = 0 ;
    for (int i = 0; i < listOfFiles.length; i++) {
      File file = listOfFiles[i];
      if (file.isFile() && file.getName().endsWith(".csv")) {
        /* do somthing with content */
          System.out.println(" File Name is ~~~~~~~~~~~~~~~~~~ " + file.getName());
          desiredNamesOfListOfFiles[idx++] =  file.getName();
      } 
    }
    System.out.println(" Length of array is " + desiredNamesOfListOfFiles.length);
    for(int j = 0 ; j < idx ; j++){

     //   System.out.println(" File name inside array is " + desiredNamesOfListOfFiles[j]);
       // ;;vars.put("VcsvFilename",desiredNamesOfListOfFiles[j]);
        strFileName = strFileName + ";" +desiredNamesOfListOfFiles[j];
        intCounter++;
    }

    count=Integer.toString(intCounter);

    vars.put("VcsvFilename",strFileName);
    vars.put("FileCounter",count);

I am not able to use this variable under CSV data config.

Does some one has any solution for it?

2

2 Answers

0
votes

CSV Data Set config is initialized during JMeter startup hence you won't be able to use a JMeter Variable as a part of file path.

Possible workarounds are in:

Both functions support multiple input files

0
votes

CSV DataSet is not able to read multiple CSV Files anyway.

And it cannot use a variable, only a property.

Why do you want to do that ?

If it's only to merge them, then an option is to use a setupThreadGroup that will merge the CSV into 1 file and you will use this file in you CSV Data Set