eeadev
eeadev

Reputation: 3852

How to add a condition in my IF CONTROLLER using jmeter and groovy

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?

Upvotes: 4

Views: 15604

Answers (2)

Dmitri T
Dmitri T

Reputation: 168002

  • 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

Upvotes: 6

timbre timbre
timbre timbre

Reputation: 13960

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)

Upvotes: 3

Related Questions