husnain
husnain

Reputation: 153

JMeter - How can I use multiple conditions in IF Controller?

Here is my code:

In If Controller -> Condition (Default Javascript) I am providing following "${responsecode}" == "404" || "${responsecode}" == "500" && "${responseMessage}" == "Not Found" image also added in fact I want to send email only in such conditions

Upvotes: 3

Views: 10388

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

Yes you can, assuming your current condition SMTP Sampler will be executed:

  • If ${responsecode} variable is 404

    OR

  • If ${responsecode} variable is 500 AND ${responseMessage} variable is Not Found


I doubt that you will get Not Found message given Response Code 500, most likely you will get an Internal Server Error there so maybe you should amend your condition to look like:

"${responsecode}" == "500" || ("${responsecode}" == "404" && "${responseMessage}" == "Not Found")

In case when If Controller doesn't behave as expected first of all check jmeter.log file for any JavaScript-related errors, it will give you some clue regarding what's wrong with your setup. You can also use __javaScript() function and View Results Tree listener combination to visualize the result of your If Controller condition:

JMeter Javascript Debug

See How to Use JMeter's 'IF' Controller article for more details on conditionally running samplers via If Controller.

Upvotes: 2

Related Questions