Jmeter – If controller example

If controller  example to control which request to send based on response of the other sampler.

We’re using Dummy Sampler to generate requests.

We also need to extract response’s code. We can use Regular Expression Extractor to get it:

  • Field to check: Response Code
  • Reference Name: RESPONSE_CODE
  • Regular Expression: (\d+)
  • Template $1$

First If Controller Condition

  • ${RESPONSE_CODE}!="200"

Second If Controller Condition

  •  ${RESPONSE_CODE}=="200"

Setup Dummy Sampler to return code 200.

Dummy Sampler - 200


if controller - yes condition

And now edit it to return something other than 200

Dummy Sampler - 404


If Controller result


Jmeter – If controller example

Jmeter’s Variables From CSV File – relative path

Jmeters Variables From CSV File config element set its base directory as a user’s home directory. If you ‘Browse’ your file it will put something like:


So in such case we need to pass base directory to be able to work with relative paths for our files.

1. Define base directory in User Defined Variables:

baseDir =>  ${__BeanShell(import; FileServer.getFileServer().getBaseDir())}

2. Use it in your element:

Jmeter’s Variables From CSV File – relative path

Use Jmeter’s base directory

You can access these variables using Beanshell as follows:

  1. JMeter’s base dir
    String baseDir = FileServer.getFileServer().getBaseDir();
    vars.put("baseDir", baseDir);
  2. JMeter’s script location (GUI mode)
    import org.apache.jmeter.gui.GuiPackage;
    String testPlanFile = GuiPackage.getInstance().getTestPlanFile();
    vars.put("testPlanFile", testPlanFile);
  3. JMeter’s script name (non-GUI mode)
    String scriptName = FileServer.getFileServer().getScriptName();
    vars.put("scriptName", scriptName); 

If you prefer you can get the same using __Beanshell() function as

${__BeanShell(import; FileServer.getFileServer().getBaseDir())}

and it will return current base directory where it is called.


Use Jmeter’s base directory