Jmeter beanshell - Error invoking bsh method:eval when trying to clear cookie/cache

416 views Asked by At

I am trying to clear cookie and cache in the middle of a thread group, so that I could login to the test application with another user. I wrote the following beanshell in jmeter.

import org.apache.jmeter.protocol.http.control.CookieManager;

CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookir_manager").getObjectValue();

ObjectValue();

clear cache.clear();

I got the below error in my jmeter logs.

Error invoking bsh method:eval Sourced file: inline evaluation of: "import org.apache.jmeter.protocol.http.control.CookirManager; ..." Token Parsing error; Lexical error at line 3, column 59. Encountered: "\u201c" (8220), after: ""

I tried to use the JSR223 post processor to clear cache using the below code:

sampler.getCacheManager().clear();
sampler.getCookieManager().clear();

But the above piece of code is acting as a global one, and starts clearing the cache and cookie for every sampler for the reminder of the script, which is causing authentication issues.

Please let me know if there's any other method to clear cache and cookie at a particular instance/sampler alone.

Is there any particular .jar to be imported to Jmeter to make this work?

1

There are 1 answers

0
Dmitri T On
  1. There is a syntax error in your script, it's not possible currently to say where exactly because your code is not full. I don't see any problems with it apart from a typo in the property name which should look like HTTPSampler.cookie_manager

  2. Since JMeter 3.1 you're supposed to use JSR223 Test Elements and Groovy language for scripting

  3. JSR223 PostProcessor obeys JMeter Scoping Rules so if you place it as a child of a particular Sampler - it will be applied to that Sampler only.

    If you put it at the same level as several Samplers - it will be applied to all of them.

  4. Wouldn't it be easier to untick "Same user on each iteration" box in the Thread Group?

    enter image description here