Question

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);
    }
}
Was it helpful?

Solution

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

OTHER TIPS

I think I can confirm this issue.

I'm not sure if it's a bug or not, but what I have found is that when running this code:

String jira_version = vars.get("jiraVersion");
if (jira_version =="7") ) {
    vars.put("closeIssueTitle_local","Done");
    vars.put("isJIRA6_local","false");
    vars.put("isJIRA7_local","true");

} else if ( jira_version.equals("6") ) {
    vars.put("closeIssueTitle_local","Close Issue");
    vars.put("isJIRA6_local","true");
    vars.put("isJIRA7_local","false");
} else {
    vars.put("closeIssueTitle_local","CLOSEISSUETITLE_BEANSHELL_FAILURE");
    vars.put("isJIRA6_local","ERROR");
    vars.put("isJIRA7_local","ERROR");
}

Where the value of jira_version is either literally 6 or 7, then the if condition always evaluates to it's last, no-match case.

when I change my evaluation condition to

if ( jira_version.equals("6") ) {

then it evaluates as expected.

Here's the rub for me. When I run this in the standalone beanshell environment, bsh-2.0b5.jar for example, it my code example works as expected. It's only within JMeter that I have to rely on .equals("X").

This does feel a bit like a bug.

This seems to be a bug with beanshell interpreter in jmeter. The regular beanshell shell does support string comparison using == . In fact, it is one of the features of beanshell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top