另一个函数内部的函数调用没有得到评估[JMeter]

Function call inside another function is not getting evaluated [JMeter]

我在 JSR223 预处理器

的另一个函数中使用函数调用
  1. 从父 HTTP 采样器获取请求正文

    String requestBody = sampler.getArguments().getArgument(0).getValue();
    log.info("Request body is : " + requestBody);
    
  2. 值在 __V 函数中得到正确处理

    log.info(${__V(requestBody)});
    
  3. 相同的 __V 函数未在 MD5 函数中求值

    String md5hash = "${__MD5(${__V(requestBody)},)}";
    log.info("md5hash is : " + md5hash);
    
  4. JMeter日志如下:

    2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: Request body is : {
        "contact":"1234567890"
    }
    2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: {
        "contact":"1234567890"
    }
    2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: md5hash is : 
    1be38aa366c4b7daef5e4b527902a97b
    

在第 4 步生成的 MD5 哈希,即 1be38aa366c4b7daef5e4b527902a97brequestBody 文本。我希望为 requestBody 变量生成 MD5。

根据 JSR223 采样器文档,不要在 Groovy 脚本中内联 JMeter Functions or Variables

The JSR223 test elements have a feature (compilation) that can significantly increase performance.

When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.

为了生成 requestBody 变量的 MD5 校验和,请使用以下代码:

def md5hash = vars.get('requestBody').md5()

有关 JMeter 中 Groovy 脚本的更多信息:Apache Groovy - Why and How You Should Use It