I am fairly new to jmeter and have been looking at creating a test plan which includes posting personal information (Dummy Data) to a website. I have a CSV File that contains around 20,000 records that I need to load into jmeter and then randomize the order of the information that jmeter will use for each iteration. Currently I am using a Beanshell Sampler to load the CSV and Randomise the lines and then a Beanshell Post Processor to load the randomised line into a variable called "Line" however after running the script and looking in my debug results it is showing parts of the data in the line/row of personal information. Investigating a little further I have realised that the Varible "Line" is being loaded with information that is being broken by due to having spaces in the string that is between the commas in the CSV file.
Example data in the CSV file as follows:
firstname,lastname,housenumber,streetname,area,postcode
john,smith,21,Albert Street,Knotts County,AB3 4DL
The code that i am using in beanshell is part1 loading the csv file :
Scanner scanner = new Scanner(new File("c:/file.csv"));
Map file = new HashMap();
int counter = 0;
while (scanner.hasNext()) {
String line = scanner.next();
file.put(counter, line);
counter++;
}
bsh.shared.fileMap = file;
bsh.shared.linesnumber = counter;
Second Part of beanshell script in a Post Processor gets random row from file and adds to variable "line":
int counter = bsh.shared.linesnumber;
Map file = bsh.shared.fileMap;
Random r = new Random();
String line = file.get(r.nextInt(counter));
vars.put("line", line);
When running this the results in the debug postprocessor show as below:
line=john,smith,21,Albert
It seems that the space between the words "Albert and Street" are breaking the line. So any string value between the comma's that includes a space breaks the line eg. streetname, postcode etc. My QUESTION is, is there a way i can load the full line in to the variable including the spaces.