Reputation: 499
I am using function call inside another function in JSR223 Pre Processor
Getting the Request Body from Parent HTTP Sampler
String requestBody = sampler.getArguments().getArgument(0).getValue();
log.info("Request body is : " + requestBody);
Value getting processed properly in __V function
log.info(${__V(requestBody)});
Same __V function is not getting evaluated inside MD5 function
String md5hash = "${__MD5(${__V(requestBody)},)}";
log.info("md5hash is : " + md5hash);
JMeter log is given below:
2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: Request body is : {
"contact":"1234567890"
}
2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: {
"contact":"1234567890"
}
2022-03-17 15:10:01,135 INFO o.a.j.m.J.JSR223 PreProcessor: md5hash is :
1be38aa366c4b7daef5e4b527902a97b
The MD5 hash generated at step 4 i.e. 1be38aa366c4b7daef5e4b527902a97b is of requestBody text. I want MD5 to be generated for requestBody variable.
Upvotes: 0
Views: 335
Reputation: 168157
Don't inline JMeter Functions or Variables in Groovy scripts, as per JSR223 Sampler Documentation:
The JSR223 test elements have a feature (compilation) that can significantly increase performance.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
In order to generate MD5 checksum of the requestBody
variable use the following code:
def md5hash = vars.get('requestBody').md5()
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
Upvotes: 1