Reputation: 432
I'm new to jmeter. I'm executing a java function which encrypts data and I'm trying to assign the output of the function in my Http request body. The function executes and I can see the response in the jmeter console but the value for some reason is not being assigned. Here's what I've tried so far :-
"key": "${__groovy(new com.util.EncUtil().encrypt(),)}"
The encrypt function in the EncUtil class encrypts the required data and returns the result. I want to assign this returned value in my Dynamic Http request. What should I change?
Upvotes: 2
Views: 277
Reputation: 168072
If you look into the Function Helper Dialog you'll see that __groovy() function has 2 parameters:
So you can amend your function to look like:
${__groovy(new com.util.EncUtil().encrypt(),encryptedValue)}
Alternative option is using vars
shorthand
${__groovy(vars.put('encryptedValue'\, new com.util.EncUtil().encrypt() as String),)}
vars
stands for JMeterVariables class instance which provides read/write access to all JMeter Variables in the thread context, check out Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn more about this and other JMeter API shortcuts available for JSR223 Test Elements and __groovy() function.
In both cases you will be able to refer the generated value as ${encryptedValue}
later on where required.
Upvotes: 2