Blazemeter:属性未在线程组之间交换

时间:2018-05-19 11:02:33

标签: jmeter blazemeter

我正在使用JMeter测试API,它在本地工作正常。但是,当我将测试计划和参数文件上传到Blazemeter时,它运行不正常并抛出错误

  

javax.script.ScriptException:ReferenceError:" getFinancialDashboard_responseCode"没有在第1行定义

在日志中。 getFinancialDashboard_responseCode是我在前一个线程组中定义的属性,它的值被传递给拆解线程组,以根据响应代码将通知推送到消息传递应用程序。

我试图在Blazemeter上的测试配置中定义此属性,但这有不同的用途,即覆盖该值。在Blazemeter上的配置中定义此属性会使测试成功执行,但会覆盖线程组中设置的当前值并使其发送不需要的通知。

以下是完整的例外日志:

2018-05-19 10:46:02,874 ERROR o.a.j.c.IfController: If_getIspDashboardData_Fails: error while processing [getFinancialDashboard_responseCode != 200;]
javax.script.ScriptException: ReferenceError: "getFinancialDashboard_responseCode" is not defined in <eval> at line number 1
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:454) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) ~[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.control.IfController$NashornJsEngine.evaluate(IfController.java:124) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.IfController.evaluateCondition(IfController.java:185) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.IfController.next(IfController.java:239) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:219) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.GenericController.next(GenericController.java:173) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.LoopController.next(LoopController.java:128) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:222) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.GenericController.next(GenericController.java:173) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.control.LoopController.next(LoopController.java:128) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:87) [ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:248) [ApacheJMeter_core.jar:4.0 r1823414]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]
Caused by: jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "getFinancialDashboard_responseCode" is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) ~[nashorn.jar:?]
at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1441) ~[nashorn.jar:?]
at jdk.nashorn.internal.scripts.Script$1$\^eval\_.:program(<eval>:1) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[nashorn.jar:?]
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) ~[nashorn.jar:?]
... 15 more

如何处理Blazemeter中的属性,以便可以在线程组之间交换值?

1 个答案:

答案 0 :(得分:0)

我强烈怀疑你的测试“在本地工作正常”,因为很可能你已经将If控制器配置为:

JMeter If Controller - BAD

在JavaScript方面不正确。如果确实在某处定义了getFinancialDashboard_responseCode,则应使用以下条件:

${__groovy(!props.get('getFinancialDashboard_responseCode').equals('200'),)}

还要确保选中Interpret Condition as Variable Expression?框:

JMeter Groovy

更多信息:6 Tips for JMeter If Controller Usage

如果您因任何原因想继续使用JavaScript,则需要将您的条件修改为:

  • 使用__P() function
  • 获取属性
  • 使用引号括起属性函数调用和200,如:

    "${__P(getFinancialDashboard_responseCode,)}" != "200"
    

但请注意,从性能角度来看,与Groovy相比,JavaScript工作得更糟。

另请注意,您应该能够联系到BlazeMeter Support,它应该更快,获得真正的专业响应的机会将远远高于社区论坛。