0
votes

I am trying to execute the following Beanshell script in JMeter and it throws an error in the log. The script is:

import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("ApiSession",props.get("MyCookie"),"","/",false,0);
manager.add(cookie);

The error in the log file is:

jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache. . . . ''

It is not happy with the line: manager.add(cookie);

If I comment it out, then the script runs, but obviously doesn't do what I want. So, not sure what the problem is.

It is not helpful that I can't see whole of the debug information. Jmeter log records only part of the actual error message (as above) and that message is cut in the middle. Switching on debugging mode doesn't help.

1
I dont see how sampler.getCookieManager() would even work. In a BeanShell sampler, that variable is not one of the defined accessible variables. You would have to define sampler as a variable like this , for it to work: HTTPSampler sampler = ctx.getCurrentSampler().djangofan
@djangofan, when I do this I get the error about missing HTTPSampler: Typed variable declaration : Class: HTTPSampler not found in namespaceShai Alon
Well, this post was from a long time ago. Not sure if things are the same in Jmeter 3.1+.djangofan

1 Answers

1
votes

If you want to see full error message you'll need to surround problematic statement in try/catch block and print stacktrace to sdtout / log.

Particularly sharing cookies between thread groups use case is highlighted in How to use BeanShell guide.