JMeter-将Beanshell用作带有文件

时间:2018-06-21 07:52:01

标签: jmeter beanshell jsr223

我有一个带有简单JSR223代码的文件:

log.info("Hello JSR223")

当我在JSR223 Sampler中选择Beanshell作为语言时,出现以下异常:

2018-06-21 10:32:28,148 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: In file: eval stream Encountered "<EOF>" at line 2, column 24.
 in eval stream at line number 2
javax.script.ScriptException: In file: eval stream Encountered "<EOF>" at line 2, column 24.
 in eval stream at line number 2
    at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:82) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:52) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_25]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:199) ~[ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:69) [ApacheJMeter_java.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) [ApacheJMeter_core.jar:4.0 r1823414]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) [ApacheJMeter_core.jar:4.0 r1823414]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]

通过添加到“脚本”字段,相同的代码无需文件即可工作

1 个答案:

答案 0 :(得分:1)

如果您使用Beanshell,则需要坚持使用Java SE 5.0语法,以使您的语句需要以分号结尾,将其修改为:

log.info("Hello JSR223");
//                      ^ this is uber important

,您的脚本应会按预期开始工作。

请注意,starting from JMeter 3.1 it is recommended to use Groovy language for scripting主要是因为Groovy has much better performance comparing to Beanshell,所以我建议将“语言”保留为groovy,在这种情况下,不需要分号。