0

When running the thread, it goes through the whole flow except for the last BeanShell assertion.

enter image description here

My BeanShell code is:

report = vars.get("status_1");

if (report=="active") {

 Failure = true;
 FailureMessage = "failed to report";

} else {

    Failure = false;


}

What could go wrong?

Amit Ronen
  • 151
  • 1
  • 4
  • 15

2 Answers2

2

You are comparing String using == you must use .equals() method to compare them.

That is generally true, not just for beanshell, but for most of the java world. Always be careful about how you compare strings. see How do I compare strings in Java?

Community
  • 1
  • 1
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • I was trying using this: `report = vars.get("status_1"); if (report.equals("active") { Failure = true; FailureMessage = "failed to report"; } else { Failure = false; }` But then for some reason it fails everything inside the IF controller – Amit Ronen Jun 22 '15 at 14:59
  • There are 2 beanshell assertions in your test plan, which one is this code for? Pay attention to the scope of an assertion. see this: http://cdn2.hubspot.net/hub/208250/file-989050882-png/Blog_Images/JMETERASSERTIONS-IMAGE1.png?t=1402378280830 – RaGe Jun 22 '15 at 15:18
  • Both "equals" and assertion scope helped. Thanks! – Amit Ronen Jun 22 '15 at 16:56
0

You can either use .equals() or boolean

 boolean report = vars.get("status_1");

 if (report) {

    Failure = true;
    FailureMessage = "failed to report";

  } else {

  Failure = false;


}