JMeter fails on beanshell imports
JMeter fails on beanshell imports
I had been using Beanshell pre-processor to add custom cookies created through javascript. While it used to work perfectly earlier, with the same line of codes I started to recieve errors in my pre-processor.
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache. . . . '' : TargetError
WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache. . . . '' : TargetError
The lines of code is as per suggestion provided in https://javaworks.wordpress.com/2011/08/05/setting-cookie-in-jmeter/
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
try{
CookieManager manager = sampler.getCookieManager();
Cookie cookie1 = new Cookie("cookie1","value","localhost","/",false,0);
manager.add(cookie1);
}catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
I came across several post in stackoverflow related to beanshell. However, none answers why imports in beanshell are failing. The error log:
018/07/02 16:24:47 ERROR - jmeter.util.BeanShellTestElement: Error in Beanshell java.lang.NullPointerException
at org.apache.jmeter.protocol.http.control.CookieManager.match(CookieManager.java:386)
at org.apache.jmeter.protocol.http.control.CookieManager.removeMatchingCookies(CookieManager.java:402)
at org.apache.jmeter.protocol.http.control.CookieManager.add(CookieManager.java:307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at bsh.Reflect.invokeMethod(Reflect.java:134)
at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
at bsh.Name.invokeMethod(Name.java:858)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BSHBlock.eval(BSHBlock.java:46)
at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
at bsh.Interpreter.eval(Interpreter.java:645)
at bsh.Interpreter.eval(Interpreter.java:739)
at bsh.Interpreter.eval(Interpreter.java:728)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:163)
at org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:186)
at org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
at org.apache.jmeter.modifiers.BeanShellPreProcessor.process(BeanShellPreProcessor.java:59)
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:786)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:445)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
at java.lang.Thread.run(Unknown Source)
1 Answer
1
First of all, there is no need in scripting, you can add custom cookies using HTTP Cookie Manager GUI
If you still want to code try upgrading to the latest JMeter version
standard
netscape
Try adding the next line to user.properties file:
CookieManager.check.cookies=false
JMeter restart will be required to pick the property up
The point it to have the HTTP Cookie Manager added to your test plan and it has to be in the Sampler's Scope. You should not need any extra jars as Cookie Manager is a part of JMeter HTTP protocol module and it should be already in your classpath. See [Modifying Cookies in JMeter with Groovy ](blazemeter.com/blog/modifying-cookies-in-jmeter-with-groovy) guide for more details on cookies manipulation from scripts if needed
– Dmitri T
Jul 4 at 13:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Dmitri, the values of the cookies in my application needs to be updated frequently within a single loop whenever user navigates to new page, so I need to use preprocessor. however, even with JSR223 I get java null point error. Do I need any extra jar when I import CookieManager/Cookie in my preprocessor?
– user2747610
Jul 4 at 12:57