'javascript exception in while controller in jmeter
I have been trying the javascript in jmeter while controller, and am using below function
${__javaScript(("${app_status_g1}".indexOf("100") == -1 && ${App_status_counter} < 10),)}
app_status_g1 is extracted from the regex extractor inside the while controller
However, I get the exception jmeter logs:
JavaScript: Error processing Javascript: [("${app_status_g1}".indexOf("100") == -1 && ${App_status_counter} < 10)]
javax.script.ScriptException: <eval>:1:45 Expected ) but found {
("${app_status_g1}".indexOf("100") == -1 && ${App_status_counter} < 10)
^ in <eval> at line number 1 at column number 45
Tried few combinations with parentheses but not able to get the cause of problem. But looks like while controller still works.
Any help will be appreciated.
Solution 1:[1]
Mind that JMeter users are strongly recommended to use JSR223 Test Elements with Groovy language and/or __groovy() function for any form of scripting as JavaScript interpreter performance might become the bottleneck and ruin your test.
So consider switching to __groovy()
function, the equivalent syntax would be:
${__groovy((!vars.get('app_status_g1').contains('100') && ((vars.get('App_status_counter') as int) < 10)),)}
Solution 2:[2]
You have to type cast ${App_status_counter}
to int from String , Because ${App_status_counter}
is a String type variable and you cannot compare it directly.
use parseInt(${App_status_counter})<10
So the condition in while loop could be
${__javaScript(("${app_status_g1}".indexOf("100") == -1 && parseInt(${App_status_counter}) < 10),)}
For more information on while loop please follow this link
and here is the link working with multiple conditions in while loop
Please let me know if it helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitri T |
Solution 2 | Rohit |