问题
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:
Use "Parameters" section of the JSR223 Test Elements like:
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