Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter enable/disable HTTP Request Sampler upon certain condition

I have a few HTTP Request Samplers that I would only like to execute when a certain condition has been met. What I have done is added a BeanShell PreProcessor to the HTTP Request Sampler with the following code

if (${getTeamName}.equals("Test Team") == true)
{
    HTTPSampler.setEnabled(false);
}

If the value of getTeamName is Test Team then I want to disable that HTTP Request Sampler, as it doesn't have to be executed then. However it looks like that currently doesn't work.

Is there any one who knows what I'm doing wrong here, or a suggestion to what I should do?

like image 988
Yves Mertens Avatar asked Apr 23 '15 13:04

Yves Mertens


2 Answers

As per JMeter Performance and Tuning Tips guide:

But of course ensure your script is necessary and efficiently written, DON'T OVERSCRIPT

Why not just to use If Controller like:

  • If Controller, condition: "${getTeamName}" != "Test Team"
    • HTTP Request Sampler

If ${getTeamName} will be Test Team child sampler(s) won't be executed.

like image 160
Dmitri T Avatar answered Oct 13 '22 00:10

Dmitri T


While using beanshell, access variables using vars.get("VARNAME")

if (vars.get("getTeamName").equals("Test Team") == true)
{
     sampler.setEnabled(false);
}
like image 37
vins Avatar answered Oct 13 '22 00:10

vins