0
votes

I have tried the below script even I have changed the path as well, but still, I am facing the same issue.

 basecost=vars.get("_baseCost");    
                 File=new FileOutputStream ("‪‪‪C:/Rajesh/Automation Stuff/rajesh.txt",true);    
             P=new PrintStream(File);    
             this.interpreter.setOut(P);    
             print(basecost);    
             File.close();    

getting below error
ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: `` File=new FileOutputStream ("‪‪‪C:/Rajesh/Automation Stuff/rajesh.txt",true); P= . . . '' : Object constructor

2
example of working beanshell script stackoverflow.com/questions/51187983/… - user7294900

2 Answers

0
votes

While looking into this, I have found that there are some encoded characters in below line of your code which are the reason for its failure.

File=new FileOutputStream (

How I found it ?

Open notepad++ and paste your code in it. Go to 'Encoding' and select 'Encode in ANSI'

enter image description here

As you click on Encode in ANSI, you will see some encoded characters (see below screenshot) in the second line of code(where Jmeter throwing error). Remove those encoded characters and use the code in Jmeter Bean-shell. It will work fine now.

enter image description here

0
votes

Don't use Beanshell for scripting, it's a form of performance anti-pattern, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language.

Example code:

new File("‪‪‪C:/Rajesh/Automation Stuff/rajesh.txt") << vars.get("_baseCost")

More information: