1
votes

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

1 Answers

3
votes

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:

    JMeter Groovy Functions

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

    JMeter Groovy Random NUmber

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