1
votes

I want to print the value of Booking ID to a output file in JMeter using Bean Shell Processor. My code:

ID = vars.get("BookingID"); 
f = new FileOutputStream("C:/BookingID.csv", true); 
p = new PrintStream(f); 
this.interpreter.setOut(p);
print(ID); 
f.close(); 

I I'm using JMeter version 3.2.

When I'm running this code I'm getting the error:

2017-07-18 09:28:11,836 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ID = vars.get("BookingID"); f = new FileOutputStream("C:/BookingID.csv", true); . . . '' : Object constructor 2017-07-18 09:28:11,836 WARN o.a.j.e.BeanShellPostProcessor: Problem in BeanShell script: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ID = vars.get("BookingID"); f = new FileOutputStream("C:/BookingID.csv", true); . . . '' : Object constructor

1

1 Answers

1
votes

Add BeanShell PostProcessor to the request. This code will work as is

ID = vars.get("BookingID"); 
f = new FileOutputStream("C:/BookingID.csv", true); 
p = new PrintStream(f); 
this.interpreter.setOut(p);
print(ID); 
f.close(); 

You may have permissions issue to write to C:\, check it by trying to to create file, or you open the file in a program as Excel or notepad and it's locked, get out of editing this file and try again.