5
votes

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?

2

2 Answers

5
votes

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.

1
votes

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

if (vars.get("getTeamName").equals("Test Team") == true)
{
     sampler.setEnabled(false);
}