Search code examples
jmeterjmeter-pluginsjmeter-4.0jmeter-3.2jmeter-maven-plugin

Jmeter check using if controller, for a variable has a value or not


in one of my steps in the Jmeter script, I'm using json extractor to read a value from a key(address) in the JSON response and store it in a variable called "TypeOfRequest." In the next step, I need to check if the "TypeOfRequest" value is null or not(There can be situations I don't find that key in the JSON response). Then I need to take a different route.

Snippet how I'm getting the TypeOfRequest from Json extractor $.communicationMethods[:1].hTTPS.address

So my question is, how do I check if TypeOfRequest has a value or not in the if controller?

tried using '${__javaScript(vars.get("TypeOfRequest") == null)}(ref https://www.blazemeter.com/blog/jmeter-if-controller and https://sqa.stackexchange.com/questions/32969/how-do-i-check-if-a-variable-is-null-using-a-if-controller) but unable to go through the if condition, can someone help me with this. Thanks in advance


Solution

  • Just use Debug Sampler to see what JMeter Variables are defined and inspect their values, my expectation is that you're "unable to go through the if condition" because your TypeOfRequest variable is not null, i.e. it's present but it's an empty string.

    Also the referenced article suggests using __groovy() or __jexl3() function so I believe if you change your condition to something like:

    ${__groovy(org.apache.commons.lang.StringUtils.isEmpty(vars.get('TypeOfRequest')),)}
    

    you will be able to "go through the if condition"