【问题标题】:Jmeter Typed variable declaration : Method InvocationJmeter类型变量声明:方法调用
【发布时间】:2016-09-24 15:07:07
【问题描述】:

我在使用 Jmeter BeanShell 预处理器时遇到问题。 该脚本调用我将它们放在目录“D:\Software\apache-jmeter-3.0\lib\ext”下的 jar。 enter image description here

这是我的 BeanShell 代码:

import com.evergrande.api.test.JsonClientUtil;
import com.evergrande.common.utils.JsonUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;

JsonClientUtil jcu=new JsonClientUtil();
ObjectNode node = JsonUtil.createObjectNode();//when I try to use the method in JsonUtil(Class),it came out error

错误:

2016/09/24 22:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 
2016/09/24 22:48:06 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 

我可以在我的 java 代码中调用“createObjectNode”方法。 那么,我该如何解决这个问题呢?谢谢大家。

【问题讨论】:

    标签: jmeter beanshell


    【解决方案1】:
    1. 不要将任何jar 放到lib/ext 文件夹中,它应该只用于JMeter 核心组件和插件。将您的 .jar 库放到其他地方的“lib”文件夹中,它们只需要在 JMeter's Claspath 上。替代选项是在Test Plan 级别上使用Add directory or jar to classpath 选项

    2. 需要重新启动 JMeter 才能拿起罐子。
    3. 您可以通过在代码周围加上try/catch 块(如

      )来获得更易读的 Beanshell 错误消息
      import com.evergrande.api.test.JsonClientUtil;
      import com.evergrande.common.utils.JsonUtil;
      import com.fasterxml.jackson.databind.node.ObjectNode;
      
      try {
          JsonClientUtil jcu=new JsonClientUtil();
          ObjectNode node = JsonUtil.createObjectNode();
      }
      catch (Throwable ex) {
          log.error("Beanshell failure: ", ex);
          throw ex;
      }
      

      因此,如果您的脚本失败,您将能够在 jmeter.log 文件中查看堆栈跟踪详细信息。另一种解决 Beanshell 脚本失败问题的方法是将 debug(); 命令添加到脚本的开头。它将触发详细输出到控制台。查看How to Debug your Apache JMeter Script 文章以获取有关 JMeter 调试技术的更多信息。

    【讨论】:

    • 谢谢!我已经解决了这个问题。这是因为缺少Jar包。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多