keylogger
keylogger

Reputation: 872

Jmeter If Controller with Groovy Function containing operator && and || doesn't work

I am creating 2 x If Controller in Jmeter 5.1.1 .

Based on the discussion in here , the expression I try is

${__groovy( (vars.get("conditionState").equals("1")) && (vars.get("NewgameConditionValue").equals(6) ) )  }

and

${__groovy((vars.get("conditionState").equals("0")) || !(vars.get("NewgameConditionValue").equals(6) ) ) }

When running it, JMeter throws Exception

for the 1st expression

org.apache.jmeter.functions.InvalidVariableException: Expected } after __groovy function call in ${__groovy( (vars.get("conditionState").equals("1")) && (vars.get("NewgameConditionValue").equals(6)
at org.apache.jmeter.engine.util.FunctionParser.makeFunction(FunctionParser.java:139) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.FunctionParser.compileString(FunctionParser.java:82) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.CompoundVariable.setParameters(CompoundVariable.java:181) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ReplaceStringWithFunctions.transformValue(ReplaceStringWithFunctions.java:46) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:170) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:80) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.PreCompiler.addNode(PreCompiler.java:89) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:994) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:995) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:995) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:977) [jorphan.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:362) [ApacheJMeter_core.jar:5.1.1 r1855137]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]

and for the 2nd

org.apache.jmeter.functions.InvalidVariableException: Expected } after __groovy function call in ${__groovy((vars.get("conditionState").equals("0")) || !(vars.get("NewgameConditionValue").equals(6)
at org.apache.jmeter.engine.util.FunctionParser.makeFunction(FunctionParser.java:139) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.FunctionParser.compileString(FunctionParser.java:82) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.CompoundVariable.setParameters(CompoundVariable.java:181) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ReplaceStringWithFunctions.transformValue(ReplaceStringWithFunctions.java:46) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:170) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:80) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.PreCompiler.addNode(PreCompiler.java:89) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:994) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:995) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:995) [jorphan.jar:5.1.1 r1855137]
at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:977) [jorphan.jar:5.1.1 r1855137]
at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:362) [ApacheJMeter_core.jar:5.1.1 r1855137]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]

I changed it to

${__groovy( (vars.get("conditionState").equals("1")) && (vars.get("NewgameConditionValue") == 6 ) )  }

It throws the same error.

But if I don't have any operator like this

${__groovy(vars.get("conditionState").equals("1") )}

it works perfectly fine.

Wondering where do I do it wrongly.

Upvotes: 1

Views: 857

Answers (1)

Felix Schumacher
Felix Schumacher

Reputation: 331

The spaces before the closing } are causing the error.

An even simpler expression to trigger this would be ${__groovy(true) }. Note the space before the closing brace.

At the moment I would consider this a bug (https://bz.apache.org/bugzilla/show_bug.cgi?id=64198)

Upvotes: 2

Related Questions