3
if(!reqAdSize.equalsIgnoreCase(hm.get("ad_size")))
{
    Failure = true;
    FailureMessage = "Ad Sizes Doesn't Match";
}

if(!reqCur.equalsIgnoreCase(resCur))
{
    Failure = true;
    FailureMessage = "Request & Responce Currency are NOT same";
}

if(!reqID.equalsIgnoreCase(resID))
{
    Failure = true;
    FailureMessage = "Request & Responce Id is NOT same";
}

In my jeMter here is my BeanShell Assertion Code all if conditions are satisfying. In result it will showing the last FailureMessage. I need to stop the execution of code if first condition is true and it will not execute further.

I tried to use the System.exit(0);andexit();. But jMeter GUI is automatically closing.
What is the method to stop the execution at current line in BeanShell.

KCS
  • 442
  • 5
  • 20

2 Answers2

3

Add return keyword wherever you want to stop the execution of BeanShell code.

Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • Thanks for the reply. It is working perfectly & I accepted the answer. Can you elaborate what was happening internally before using **return** keyword and after using **return** keyword. – KCS Nov 15 '16 at 10:27
  • It is same as Java keyword "return". If you know Java, you know what "return" keyword means right. It will stop the execution the moment you called return keyword and give back the execution control to the CALLER. You can also add arguments to return like "return reqVar1" to the caller. – Naveen Kumar R B Nov 15 '16 at 10:32
0

You have SampleResult pre-defined variable in the Beanshell Assertion, it is a shorthand for org.apache.jmeter.samplers.SampleResult class. Take a look into following methods:

Something like:

if (!reqAdSize.equalsIgnoreCase(hm.get("ad_size"))) {
    Failure = true;
    FailureMessage = "Ad Sizes Doesn't Match";
    SampleResult.setStopTest(true);
}

Guide on Beanshell scripting in JMeter context: How to Use BeanShell: JMeter's Favorite Built-in Component

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Dmitri, he asked to stop the execution of the code which is present in Bean Shell Assertion, but NOT to step the entire test. please refer the last line "What is the method to stop the execution at current line in BeanShell." @Chaitanya, please confirm what you are expecting? stopping the test? or stopping the beanshell execution code? – Naveen Kumar R B Nov 15 '16 at 10:17
  • Dmitri I need to stop the beanshell execution code. @Naveen is right – KCS Nov 15 '16 at 10:44