Parsing string to integer in BeanShell Sampler in JMeter

梦想的初衷 提交于 2019-12-04 08:11:43

Your code looks good however it can be a problem with currentPMCount and/or pmViolationMaxCount variables.

If they really look good and look like Integers and don't exceed maximum/minimum values of Integer you can try the following:

  1. Make sure that there are no "space" characters around number value as leading or trailing space will cause conversion failure. Perhaps invoking trim() method on variable can help:

    int i = Integer.parseInt(vars.get("currentPMCount").trim());
    
  2. If you store your script into a file and then provide path to the file in Beanshell Assertion you'll get "problematic" line number
  3. My favourite: surround your code into try/catch block as follows:

    try{
        //your code here
    }
    catch (Exception ex){
        log.warn("Error in my script", ex);
        throw ex; // elsewise JMeter will "swallow" the above exception
    }
    

This way you'll get more informative stacktrace instead of lousy Error invoking bsh methodmessage which tells nothing.

See How to use BeanShell: JMeter's favorite built-in component guide for more tips and tricks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!