JMeter - 在脚本中提交 JMeter 函数(JSR223 元素) [英] JMeter - submit JMeter function inside a script (JSR223 element)

查看:19
本文介绍了JMeter - 在脚本中提交 JMeter 函数(JSR223 元素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数对于编写函数式脚本非常有用,而且无需编写真正的代码也很有帮助.

目前我可以在大多数测试计划中执行函数,例如 JSR223 采样器的脚本.

有没有办法在 JSR223/Beanshell 脚本中启用 JMeter 功能?例如 ${__log(Message)} 或 ${__Random(0,10)}

如果将变量调用为 ${..} 是一个问题,是否有调用函数的解决方法?

可能在groovy脚本中调用groovy函数会出现问题,但是其他函数可以执行吗?

解决方案

不应该内联

  • 寻找基于代码的等价物,即使用

  • 更多信息:Apache Groovy - 为什么以及如何使用它

    Functions are very useful for writing a functional script and also helpful without writing real code.

    Currently I can execute functions in most of Test Plan except in Script of JSR223 Sampler for example.

    Is there a way to enable JMeter function inside JSR223/Beanshell script? For example ${__log(Message)} or ${__Random(0,10)}

    If the call for variable as ${..} is an issue, is there a workaround for calling a function?

    Maybe there will be a problem calling groovy function inside groovy script, But can other functions be executed?

    解决方案

    You should not be inlining JMeter functions and/or Variables into scripts as :

    • They might resolve into something causing compilation failure or unexpected behavior
    • In case of Groovy they will conflict with GStringTemplate, moreover compiled scripts caching will not be possible

    So you have 2 options:

    1. Use "Parameters" section of the JSR223 Test Elements like:

    2. Go for code-based equivalents, i.e. using RandomUtils class:

    More information: Apache Groovy - Why and How You Should Use It

    这篇关于JMeter - 在脚本中提交 JMeter 函数(JSR223 元素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆