Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
731 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...