I want to parameterize the filename textfield of CSV dataset config. I am writing into different files for every user that I'm using in JMeter, hence I need to parameterize the filename option in the CSV dataset config to read the files I create for every user. How can i do that?
I'm using a user-defined variable called csvFilename which I'm referring to as ${csvFilename}
in the filename option of CSV dataset config element. I'm writing into this variable the path of the filename from a BSF post-processor:
vars.put("csvFilename","/home/abhijeet/load_test_plans/users//"+username+".csv");
(BFS post-process enables reading variables from JMeter). In the above line of code, a username is another variable that will change according to the username I fetch from a CSV file.
So my problem is that the variable ${csvFilename}
is not replacing the file's path into the Filename textfield of CSV dataset config. Am I missing something?
-
I also tried this: I used a BeanShell script function in the path to place the username in the filename textfield of CSV dataset config like this: /home/abhijeet/load_test_plans/users/${__BeanShell(vars.get("username"))}.csv But this is not working too. Could someone please help me?Abhijeet Vaikar– Abhijeet Vaikar2012年07月11日 13:27:39 +00:00Commented Jul 11, 2012 at 13:27
1 Answer 1
Since I could not find any solution to this problem I'm facing I implemented a workaround for it by writing code into a BeanShell PreProcessor that would work like a CSV dataset config element.
The code i've written is:
import java.io.*;
String uname = vars.get("username");
System.out.println("Username at the preprocessor: "+uname);
String file_path="/home/abhijeet/load_test_plans/users//"+uname+".csv";
FileReader f = new FileReader(file_path);
BufferedReader reader = new BufferedReader(f);
String line = null;
String pt_id, first_name, last_name;
int file_counter = 0;
int gbcount = Integer.parseInt(vars.get("global_counter"));
while((line = reader.readLine()) != null){
if(file_counter == gbcount){
String[] fields = line.split(",");
pt_id = fields[0];
first_name = fields[1];
last_name = fields[2];
vars.put("patientID",pt_id);
vars.put("fname",first_name);
vars.put("lname",last_name);
break;
} else {
file_counter++;
}
gbcount++;
vars.put("global_counter",String.valueOf(gbcount));
-
please click the check box next to your answer so that your question can be removed from the unanswered list.user246– user2462013年08月12日 16:34:34 +00:00Commented Aug 12, 2013 at 16:34
Explore related questions
See similar questions with these tags.