Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter "if controller" with parameters?

Tags:

jmeter

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?

like image 286
Ben Flynn Avatar asked Apr 18 '11 12:04

Ben Flynn


People also ask

How if controller works in JMeter?

The If Controller allows the user to control whether the test elements below it (its children) are run or not. By default, the condition is evaluated only once on initial entry, but you have the option to have it evaluated for every runnable element contained in the controller.

What is ${ JMeterThread Last_sample_ok?

As we mentioned before, ${JMeterThread. last_sample_ok} function returns the result of the previous request sampler, while the 'Evaluate for all children? ' parameter tells JMeter to verify the condition against each child request samplers. Therefore, if the previous request is successful, then ${JMeterThread.

What is JSR223 sampler in JMeter?

JMeter Sampler elements allow taking actions in any place in the test, without depending on a specific request. In this example a JSR223 sampler will be used to send HTTP requests to either BlazeMeter or JMeter websites, based on the thread id.


2 Answers

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

"${my_variable}"=="foo" 
like image 91
jameshfisher Avatar answered Sep 19 '22 08:09

jameshfisher


You can simply use something like

${my_variable}=='1' 

Sometimes JMeter documentation can be confusing :)

Edit 27 september 2017:

The answer here works but has a very bad performance impact when number of threads exceeds 40.

See below for correct and most performing answer:

  • https://stackoverflow.com/a/46976447/460802

See:

  • https://bz.apache.org/bugzilla/show_bug.cgi?id=61675
like image 24
Gerrie Schenck Avatar answered Sep 17 '22 08:09

Gerrie Schenck