0

I am currently doing the Blazemeter Jmeter Pro certification and while following through I have 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 have got no clue and am just dumbstruck with this issue. This happened to me with other lecture videos as well. I am guessing some settings is missing here about which I do not know. P.S. This is the function mentioned in the picture - {"token": ${__groovy(new StringBuilder().append(${counter_variable}).append(${password_variable}).append(${time_variable}),)}}

Any help?

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

| improve this answer | |
0

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

| improve this answer | |

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.