Helping Hands
Helping Hands

Reputation: 5396

How can I use If controller with Beanshell postprocessor

Here is map what I am looking for :

  1. If user login as retailer then follow specific requests
  2. If user login as reseller then follow specific requests

What I have done for retailer :

  1. I have added one HTTP POST request to login as retailer
  2. Also added BeanShell PostProcessor to get URL of previous request which will be return by above login post request.
  3. I have added following code into BeanShell PostProcessor to make sure if returned URL contains any word like "retailer" or not.

Code :

String URL = prev.getURL().toString();
vars.put("URL", URL);

if (vars.get("URL").contains("retailer")) {
    log.info("PASS");
} else {
    log.info("FAIL");
}

Above code works well.

  1. Next I have added IF controller and added all Retailer related HTTP requests under this IF controller. Now I am not sure what exactly I should write for If controller to tell if previous URL contains word "retailer" then follow all HTTP requests which are under IF controller.

I tried following for IF controller but seems not working :

"${URL}".contains("retailer")

I feel like jmeter ignoring IF controller as I am not getting any error.

Goal is to execute specific requests based on user role like retailer/reseller.

Upvotes: 0

Views: 698

Answers (1)

Dmitri T
Dmitri T

Reputation: 168122

You don't have contains() function in JavaScript, you need to use indexOf() function instead so your If Controller condition should be like:

"${URL}".indexOf("retailer") != -1

Remember to always look into jmeter.log file when your test doesn't work as expected, in 99.9% of cases you can figure out the reason from it.

Upvotes: 1

Related Questions