Search code examples
javajmeterbeanshell

How to know exact the line and description of error which is occurred when executing BeanShell program in jMeter


Assertion error: true
Assertion failure: false
Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: source   Sourced file: ../../InputFiles/Scripts/minimal-json.bsh

This error is occurring when I am executing my BeanShell program.
I checked jmeter.log file and it is giving similar error.

2016/11/15 16:11:40 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: source Sourced file: ../../InputFiles/Scripts/minimal-json.bsh 
2016/11/15 16:11:40 WARN  - jmeter.assertions.BeanShellAssertion: org.apache.jorphan.util.JMeterException: Error invoking bsh method: source    Sourced file: ../../InputFiles/Scripts/minimal-json.bsh 

By using try and catch, I got the exception and store it in log.info(e). But it was also giving the same error.


How to get exact error line & description of the error(like variable is not defined or No such method,etc.,).


Solution

  • log.info(e) contains the error itself as String is expected and you pass Exception there. I would suggest using another method, to wit: Logger.error(String message, Throwable throwable) like:

    try {
        int i = 1 / 0;
    }
    catch (Throwable ex) {
        log.error("Error in Beanshell: ", ex);
        throw ex;
    }
    

    It will work like:

    Beanshell try/catch

    Another troubleshooting techique is adding debug() directive to the beginning of your Beanshell script - this way you will get exhaustive information on your script executin in stdout

    See How to Debug your Apache JMeter Script article for more details.