3

I am running a JMeter test and hoping to read in some values from a CSV (due to other reasons, I cannot use the CSV Data Set Config which I normally use to read CSVs. This is due to the order in which CSVs are loaded/read within the test).

Using a BeanShell pre-processor, I have used the script below to read in the file so I can parse through and find the value I need - at this point, I am just trying to input the file, then I will add more in the script to actually parse the data.

docFile=new File("C:/Dev/jmeter-support.csv"); 
BufferedInputStream bin; 

bin = new BufferedInputStream(new FileInputStream(docFile)); 
while(bin.read()!=-1){} 

bin.close(); 

However, the error below is stumping me. I have tried declaring the object type of variables beforehand, but the same error continues to persist. It is unclear what may be causing the error in this script.

jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   
Sourced file: inline evaluation of: ``//String fileName = vars.get("skillsFile");  docFile=new File("C:/Dev/jmeter-sup . . . '' : Object constructor 
krodmannix
  • 845
  • 10
  • 30

2 Answers2

0

I just tried. Your script is correct and i do not see any error. Please check if the file is present in the path - C:/Dev/jmeter-support.csv

enter image description here

vins
  • 15,030
  • 3
  • 36
  • 47
  • Thank you for trying. I'll give it a shot - while I am hoping this may be the reason behind the error, at the same time I'll be kicking myself if it is :p – krodmannix Jul 10 '14 at 17:33
  • Please let me know if it is some other issue - i would like to learn :) – vins Jul 10 '14 at 17:40
  • This is not the issue - I tried on multiple files and it still fails to work. What version of JMeter are you using? – krodmannix Jul 10 '14 at 19:07
  • Also, did you run this as a PreProcessor or Sampler? – krodmannix Jul 10 '14 at 19:07
  • hm..ineteresting..i use version 2.11 - I chked in both v2.9 and v2.11. It works. I also tried in Beanshell pre/post processors & Beanshell sampler. It works. Can you show the complete code? can you try to see if 'fileName' variable is not null. – vins Jul 11 '14 at 02:40
-1

Try to use a Try Catch Block in your Bean Shell script, so that it will give you more details on the exact exception issue. For example:

try{
docFile=new File("C:/Dev/jmeter-support.csv"); 
BufferedInputStream bin; 

bin = new BufferedInputStream(new FileInputStream(docFile)); 
while(bin.read()!=-1){} 

bin.close(); 

}

catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}

For the exception, looks like the forward spaces in the file path is having issues which you can see looking at the detailed exception using above try-catch. Can you please try with "C:\Dev\jmeter-support.csv" instead of "C:/Dev/jmeter-support.csv"