JMeter - submit JMeter function inside a script (JSR223 element)

雨燕双飞 提交于 2019-12-19 11:05:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/47305382/jmeter-submit-jmeter-function-inside-a-script-jsr223-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!