Sumana
Sumana

Reputation: 11

Unable to print the response value to a output file in Jmeter 3.2 using Bean Shell Processor

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

Upvotes: 1

Views: 1170

Answers (1)

Ori Marko
Ori Marko

Reputation: 58774

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.

Upvotes: 1

Related Questions