0

I am currently following the 'Blazemeter Jmeter Pro' certification training and while working on an exercise, I noticed that for some reason, the groovy functions aren't working for me. Let me show you:

I wrote a couple of functions in a dummy sampler like this: Notice the different functions in the request and response sections

Then when I ran, I got the username, password and time as expected Look at the request section

but the token response is just empty. enter image description here

I got no clue and am just dumbstruck with this issue. This happened to me with the other lecture videos as well. I am guessing that this is a configuration issue. Any help is appreciated.

P.S. This is the function mentioned in the picture:

{"token": ${__groovy(new StringBuilder().append(${counter_variable}).append(${password_variable}).append(${time_variable}),)}}
1

Don't ever inline JMeter Functions or Variables into Groovy scripts, if you want to access the variable value use vars shorthand instead, it stands for JMeterVariables class instance and provides read/write access to all the JMeter Variables in the current thread scope.

You need to change this:

{"token": ${__groovy(new StringBuilder().append(${counter_variable}).append(${password_variable}).append(${time_variable}),)}}

to this:

{ "token" : ${__groovy(new StringBuilder().append(vars.get('counter_variable')).append(vars.get('password_variable')).append(vars.get('time_variable')).toString(),)} }

More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

1
  • Thanks Dmitri for this tip.
    – Mishal
    Feb 8 at 7:47
0

Okay! So I have figured it out the reason by just writing it over here Damn!

Just posting it here so that someone might find it useful -

Apparently I had added a couple of randomized alphabets along with numbers in the password variable which gets appended to the token variable.

Whenever an alphabet comes into the string, it doesn't work and returns a blank line.

I changed it to just numbers like this - enter image description here and voila! enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.