Take the 2-minute tour ×

I was reading the JMeter documentation and came across this info box about "If Controllers":

No variables are made available to the script when the condition is interpreted as Javascript. If you need access to such variables, then select "Interpret Condition as Variable Expression?" and use a __javaScript() function call. You can then use the objects "vars", "log", "ctx" etc. in the script.

I don't quite follow this. Does this mean if I want access to a "User Defined Parameter" then I can access it only by writing some JavaScript? The example that follows this box then refers to "${COUNT}"

Could someone clarify the usage of the If Controller, maybe with an example or two?

share|improve this question
add comment

6 Answers

up vote 6 down vote accepted

You can simply use something like


Sometimes JMeter documentation can be confusing :)

share|improve this answer
Thanks. Other things I noticed: Above expression works with or without quotes. To compare strings, user defined variable value must be double quoted. If unquoted boolean used (true/false) in UDV, the variable can be used by itself as the condition (i.e. MY_VAR=true, if ${MY_VAR} then) –  Ben Flynn Apr 18 '11 at 13:09
Actually I took my example code from a working project, where I check for the string '1'.But maybe it's because it's a char that it works with single quotes? –  Gerrie Schenck Apr 18 '11 at 19:16
Yes, I think it might be doing a character comparison in that case... –  Ben Flynn Apr 18 '11 at 19:58
OK, more info on String matching. Suppose MY_VAR = apples. ${MY_VAR} == "apples" # => returns false. "${MY_VAR}" == "apples" # => returns true. Suppose MY_VAR = "apples". ${MY_VAR} == "apples" # => returns true. "${MY_VAR}" == "apples" # => returns false. If you set a variable in a BeanShell, vars.put("MY_VAR","apples"); then you are in first case. You could do vars.put("MY_VAR","\"apples\""); but you're probably better off just putting the variable name in quotes for an If Controller string comparison. –  Ben Flynn Apr 19 '11 at 15:45
add comment

As Gerrie said you need to check your variable

${my_var} == 'value'

But be careful with the 'User Defined Variables'

Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.

That basically means that you cannot define 'User Defined Variables' inside an 'If Controller'. Take a look to the 'BeanShell' instead.

share|improve this answer
This is good additional info. –  Ben Flynn Apr 18 '11 at 13:10
add comment

UNCHECK the CHECKBOX "Interpret condition as variable expression"

I wasted a couple of hours without unchecking this checkbox. It worked with and without semicolon(;) at the end of the statement. Make sure that you have set the User-Defined Variables before calling the if controller.

All the following variations worked for me in Jakarta Jmeter 1.5

  • ${__javaScript("${HOMEPAGE}"=="Y")}
  • "${HOMEPAGE}"=="Y"
  • "${HOMEPAGE}"=="Y";
share|improve this answer
add comment

God bless the http://habrahabr.ru Have tried until found these. enter image description here

Using the quotes was my solution.

share|improve this answer
add comment

All these answers are wrong! You need to put the variable reference in quotes, like so:

share|improve this answer
add comment

Replace: ${my_variable}=='1' with "${my_variable}" == "1"

share|improve this answer
add comment

Your Answer


