Learn JMeter in 5 Hours

Start Learning
Slack

Test Your Website Performance NOW!

arrow Please enter a valid URL
Jul 23 2012

How to Use JMeter's 'IF' Controller

In previous articles we reviewed some nifty little tricks for building test plans using JMeter. You can easily develop scripts which will execute several HTTP Requests with or without any data.

 

But what will you do if you need to execute HTTP Requests based on a specific condition?

 

Don't worry, it's easy as pie. JMeter has this functionality called the “IF Controller”. The IF Controller allows the user to control whether the test elements below (the children) are run or not. 

 

JMeter\s IF Controller in action

 

It has the following fields:

 

Name.

 

Descriptive name for the controller shown in the tree.

 

Condition

 

By default (default Javascript), the condition is interpreted as a Javascript code that returns "true" or "false", but this can be overriden with the following option;

 

Interpret Condition as Variable Expression

 

If this is selected, then the condition must be an expression that evaluates to "true" (case is ignored). Example, ${FOUND} or ${__jexl(${VAR} > 100)}. Unlike the Javascript case, the condition is only checked to see if it matches "true" (case is ignored).

 

Evaluate for All Children

 

Should the condition be evaluated for all children? If not checked, then the condition is only evaluated on entry.

 

Examples:

 

“Condition field” can be either variable or javascript expression. The most used case with variable is:"${VAR}" == "abcd"
If “${VAR}”==”abcd” is true, than the child request will be executed. In the case, if “${VAR}”==”abcd” is false, than the child request will be ommited by the JMeter engine.
Javascript expression has the same usage.

 

A common headscratcher now has an answer.......

 

How to use the IF controller for running HTTP Requests depending on previous request results?

 

The answer is very simple, just use the following condition in the IF Controller:

 

“${JMeterThread.last_sample_ok}”

 

See? Super quick lesson.

 

     
arrow Please enter a valid URL

You might also find these useful:

Interested in writing for our Blog?Send us a pitch!