在 Jmeter 的 beanshell 预处理器中访问输出变量时出错

Error on accessing Output Variable in beanshell preprocessor in Jmeter

我无法在 Jmeter 中的 Beanshell Pre/Post-processor 中打印 foreach 控制器的 'Output Variable' 值。

log.info("inside hash"+ ${current_file} ); //current_file is the Output variable name defined in foreach controller and has the value of current file path.
File file=new File(${current_file});
byte[] content = FileUtils.readFileToByteArray(file);

每当我执行测试时,我都会收到此错误:

2021-12-15 19:58:25,208 错误 o.a.j.u.BeanShellInterpreter:调用 bsh 方法时出错:eval 在文件中:内联评估:``import org.apache.commons.io.FileUtils;导入 org.apache.jmeter.services.FileSe 。 . . '' 在第 4 行第 9 列遇到 "( "inside hash" + C :"。

谁能帮我解决这个错误?

  1. 不要内联 JMeter functions or variables in form of ${current_file}, use vars shorthand for JMeterVariables class 实例

    类似于:

    String current_file = vars.get("current_file");
    log.info("inside hash"+ current_file );
    File file=new File(current_file);
    
  2. Don't use Beanshell, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language 对于脚本,您的代码有可能在切换到 Groovy 后才开始工作,或者至少您会得到更多信息性错误。