0
votes

I am struggling with the cookies to clear after certain step. This is what I have in a sample test plan

enter image description here

enter image description here

enter image description here

enter image description here

I am getting a data from CSV file and then I have multiple cookies - which are location IDs which I need to pass for each row from CSV. I have tried using the Cookie Manager with option to clear iteration which works fine for next row from CSV but not to loop through cookie list defined in the user defined variable. I looked at this article I have tried adding this code at the same level as the HTTP request but get an error

2

2 Answers

0
votes

sampler.getCookieManager().clear() function should do the trick for you

Demo:

enter image description here

Given you're getting an NPE most probably something is wrong with your HTTP Cookie Manager configuration, you can try enabling debug logging for it to see if JMeter "complains" on anything and if it does - fix the HTTP Cookie Manager configuration accordingly.

In order to get extended debug information for the HTTP Cookie Manager add the next line to log4j2.xml file:

<Logger name="org.apache.jmeter.protocol.http.control.CookieManager" level="debug" />

JMeter restart will be required to pick the property up.

0
votes

Anyone looking for the answer it was quite simple in my case. I just had to add the blank Cookie Manager

Header Cookies

Earlier I had these filled with the values which was causing some issues. Now I have added the JSR223 PreProcessor with this code and it worked fine

import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
Cookie newCookie;
CookieManager manager = sampler.getCookieManager();
location = vars.get("locationID_"+ vars.get("counter"))
Cookie myCookie = new Cookie("location_ID", location, google.com"/",false , 0);
manager.add(myCookie);