Sunday, July 10, 2011

JMeter Tip - javascript eval

For my jmeter script, I was trying to set a javascript statement for this formula --> pitia=${cpi}+${cti}+(${eshortage}/60)
I used the code like this --> ${__javaScript( eval ('${cpi}'.concat('+'\,'${cti}'\,'+'\,'${eshortage}'\,' /60' ) ) )}
The above one was working in a simple script and it is not worked in my business script.

In jmeter.log, I got the exception like below:
2011/07/07 17:30:30 ERROR - jmeter.functions.JavaScript: Error processing Javascript org.mozilla.javascript.EcmaError: SyntaxError: missing ; before statement (<cmd>#1(eval)#1)
at org.mozilla.javascript.ScriptRuntime.constructError(
at org.mozilla.javascript.DefaultErrorReporter.error(
at org.mozilla.javascript.Parser.addError(
at org.mozilla.javascript.Parser.reportError(
at org.mozilla.javascript.Parser.statementHelper(
at org.mozilla.javascript.Parser.statement(
at org.mozilla.javascript.Parser.parse(
at org.mozilla.javascript.Parser.parse(

The reason for failure is a simple space, which was given for variable 'cpi'. The jmeter error did not indicate the right reason. You should debug each variable.

No comments: