Search code examples
testingjmeterload-testingstress-testingbeanshell

If condition not working in Bean shell sampler


I am writing following script in Bean Shell sampler but it is not executed properly,

JMeter never enters in 'if' condition, what I m doing wrong?

*WRIDTEMP is a variable, WRId is a variable having value retrieved from a csv file.

if((vars.get("WRIDTEMP")==vars.get("WRId")) || vars.get("WRIDTEMP")==0)
{
    String i = vars.get("C"); 
    int counter = Integer.parseInt(i); 
    counter++; 
    vars.put("C", "" + counter); 

    if(counter<10 )
    {
        vars.put("Message",temp+authString);
    }
}

Solution

  • You are comparing String using == , you must use .equals() method to compare them. to compare to 0, you should do .equals("0")