2

I have a HTTP request sampler configured. In the request body, I call out to a beanshell function I wrote:

${__BeanShell(createHeader("GET"\,"Customer"\,"${__UUID}"\,"${__time(yyyy-MM-dd'T'hh:mm:ss)}"))}

The function just builds some request strings with the passed-in parameters. I want to remove the jmeter function calls (__UUID and __time), and call them directly from within the beanshell function. I could not find a way to do that. Thanks

OldProgrammer
  • 12,050
  • 4
  • 24
  • 45

1 Answers1

2
  1. Don't inline JMeter Functions or Variables into scripts, in your case you will have to go for code-based equivalents instead, to wit:

    • __UUID() -> UUID.randomUUID().toString()
    • __time() -> new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date())
  2. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, in your case it would be __groovy() function. If you want to re-use createHeader method - you can put it into a separate .groovy file and define groovy.utilities property pointing to this file.

    See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for the info! – OldProgrammer Mar 21 '19 at 14:54
  • An odd thing is that in the official doc https://jmeter.apache.org/usermanual/functions.html on JMeter functions and variables there's no clear and thorough list of code-based equivalents of those. So for example __threadNum() translates to ctx.getThreadNum() . And it's explicitly stated in the reference of the function. But for some others it's hard to find the equivalents right away. – Alexander Ites Jun 17 '21 at 09:33