0

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
Kailai
  • 1
  • 1
  • @dmitri T, Thank you much for the response. Kindly allow me to explain the scenario here. We are faced with a situation where, we are initially logging in with one user, and we are required to login with another user in the same thread group. Issue is, right now we are unable to log out of the application because of a bug, hence clearing cache and cookies is the solution to log out and login with another user. The above posted beanshell code is the complete code I had tried to use in a Beanshell preprocessor, just apologies for the typo in cookie*. – Kailai Jan 05 '22 at 06:08
  • @dmitri T, Regarding the JSR223 postprocessor, I have placed the postprocessor as a child for the sample, but still it is clearing cookies for all the following samples. If there was any existing code in beanshell to clear cache and cookies for a particular instance alone, kindly help to provide it. – Kailai Jan 05 '22 at 06:11

1 Answers1

0
  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

Dmitri T
  • 159,985
  • 5
  • 83
  • 133