【问题标题】:JMeter - Replace inline javaScript to BeanShellJMeter - 将内联 javaScript 替换为 BeanShell
【发布时间】:2021-08-29 17:41:43
【问题描述】:

我需要在每个请求的标头中发送经过的时间。为此,我在 HTTP 标头管理器中使用内联 javaScript,如下所示:

如果有什么方法可以用 BeanShell 而不是 javaScript 做同样的事情?

【问题讨论】:

    标签: javascript jmeter beanshell


    【解决方案1】:

    我认为since JMeter 3.1 you are supposed to be using JSR223 Test Elements and Groovy language for scripting 所以这里是__groovy() function 类似的东西:

    ${__groovy(((System.currentTimeMillis() - (vars.get('TESTSTART.MS') as long)) / 1000).round(1),)} 
    

    更多信息:Apache Groovy - Why and How You Should Use It

    【讨论】:

    • 只是一个小注释 - 以整数形式返回秒数(如在我的 javascript 示例中) - round(1) 应更改为 round(0) 甚至只是 round()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2016-06-12
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多