javascript - 如何修复while控制器中的Javascript错误?
问题描述
我在我的 Jmeter 脚本中使用 While 控制器。我在 while 控制器中给出了以下条件
${__javaScript(${counter} < 10)}
尽管条件按预期工作,但它会在日志中引发以下错误。
2019-02-02 15:58:21,315 ERROR o.a.j.f.JavaScript: Error processing Javascript: [${counter} < 10]
javax.script.ScriptException: <eval>:1:1 Expected ; but found {
${counter} < 10
^ in <eval> at line number 1 at column number 1
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:537) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:524) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) ~[nashorn.jar:?]
at org.apache.jmeter.functions.JavaScript.executeWithNashorn(JavaScript.java:142) [ApacheJMeter_functions.jar:3.2 r1790748]
at org.apache.jmeter.functions.JavaScript.execute(JavaScript.java:103) [ApacheJMeter_functions.jar:3.2 r1790748]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:141) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:116) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.WhileController.getCondition(WhileController.java:124) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.WhileController.endOfLoop(WhileController.java:56) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.WhileController.next(WhileController.java:102) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:219) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.GenericController.next(GenericController.java:173) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.LoopController.next(LoopController.java:123) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:219) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.GenericController.next(GenericController.java:173) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.control.LoopController.next(LoopController.java:123) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:87) [ApacheJMeter_core.jar:3.2 r1790748]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:274) [ApacheJMeter_core.jar:3.2 r1790748]
有人知道这个错误背后的原因吗?如何解决?
解决方案
可能是您的变量在While 循环${counter}
的第一次迭代期间未定义的情况,选项位于:
- 使用即用户定义的变量给
${counter}
变量一个初始值 - 检查
counter
变量是否设置使用ie __isVarDefined() 函数
但是,您可以通过迁移到__groovy() 函数(顺便说一下,这是自JMeter 3.1以来推荐的脚本选项 ),用一块石头杀死两只鸟,条件是:
${__groovy(vars.get('counter') == null || (vars.get('counter') as int) < 10,)}
推荐阅读
- html - 如何在某个特定位置对齐两条线
- nlp - IBM Watson:正确的意图粒度应该是什么?
- sql - SQL-查询加入3个表,按特定列分组并按年份过滤?
- ios - 使用带有隐藏导航栏的 UISplitViewController 时的屏幕边缘手势
- python - 谷歌日历 API 得到更新继续给 404
- nativescript-angular - Nativescript Angular - 无法在 RadListView 的第一项上触发 itemSelected
- python - 我在 CodeSculptor3 上制作的这个 3d 相机的旋转有什么问题,CodeSculptor3 是一个带有 GUI 的基于浏览器的 Python 解释器?
- python - Jupyter:运行模型
- r - 使用 dplyr 排列行时引用循环中的变量
- amazon-s3 - 无法直接导航到托管在 s3 + cloudfront 上的网站