3

I am using jmeter 3.3 and groovy and have a IF CONDITION which filters according to the response code.

here is what I am doing and it works:

${__jexl3(${code} != 000)} 

Now I want to add an AND logic to this condition or an OR logic

for instance doing this:

${__jexl3(${code} != 000)} && ${__jexl3(${code} != 901)}

but this does not seem to work.

what is the proper way of adding logic operator?

eeadev
  • 3,662
  • 8
  • 47
  • 100

2 Answers2

5
  • If you want JEXL you need to use a single function call rather than 2 separate:

    ${__jexl3("${code}" != "000" && "${code}" != "901" ,)}
    
  • If you want to use Groovy - refer the variable as vars.get('code') like:

    ${__groovy((!vars.get('code').equals('000') && !vars.get('code').equals('901')),)}
    

More information: 6 Tips for JMeter If Controller Usage

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
2

If your change the statement to

${__jexl3(${code} != 000 && ${code} != 000)} 

it will work (i.e. you pull both conditions under the same jexl3 evaluation).

The thing is, you don't need jexl3 evaluation at all. Your If Controller will use JavaScriptby default, and thus can be configured like this:

enter image description here

So your code can be

${code} != 000 && ${code} != 000

(of course it doesn't make much sense to put same condition there, but I assume it's an example)

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
  • Advising to use Javascript, while it works, is not ideal. As the jmeter5 UI indicates now, for performance it's best to use groovy or jexl3. – Jon L. May 03 '21 at 16:36
  • 1
    @JonL. This is a 3-year old answer. I didn't deal with Jmeter for a long time, but back in the day you had to install groovy separately. So doing that for a sake of a small performance benefit of a simple comparison is not ideal either (it's called a premature optimization). – timbre timbre May 31 '21 at 22:09