Cookies won't reset on iteration in JMeter 'Loop Controller'?

Using Jmeter 2.12, what can cause cookies to fail before reset during JMeter Loop Controller? I tried everything I could think of, but each time in the loop one of the cookies from the previous entry remains. This is actually not like cookies.

This is how I put together my loop:

Thread Group 1 -- Loop Controller (3x) -- Simple Controller -- HTTP Header Manager -- HTTP Cookie Manger (with 'Clear cookies each iteration?' enabled) -- BeanShell sampler - with code that tries to clear all cookies -- HTTP /login (gets cookies and auth headers) -- ... various HTTP Samplers ... -- HTTP /logout 

I tried adding a Beanshell sampler with this code (as shown above), but it does nothing:

 import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache.jmeter.protocol.http.control.HeaderManager; CookieManager cManager = sampler.getCookieManager(); cManager.clear(); HeaderManager hManager = sampler.getHeaderManager(); hManager.clear(); 
+5
source share
2 answers
  • Loop controller does not increase iteration. You can verify it by evaluating the vars.getIteration () Beanshell code line. The iteration is increased at the Thread group level. To override this, you can call the vars.incIteration () method on any Beanshell-enabled test item (Sampler, Pre / Post Processor, Assertion, etc.). )
  • The Beanshell code to clear cookies actually does nothing, since the cManager instance cManager not return back to the sampler. You need to change your code as follows:

     CookieManager cManager = sampler.getCookieManager(); cManager.clear(); sampler.setCookieManager(cManager); 

    So sampler may have an instance of "cManager" with cleared cookies

See How to Use BeanShell: JMeter is a favorite built-in component for more information on Beanshell scripts in Apache JMeter.

+3
source

Ok, I understood the problem. Despite the fact that the “HTTP Cookie Manager” has the option “Clear cookies at each iteration”, the “iteration” that it talks about does not include the Loop controller. These include only Thread Group iterations / loops. It was incomprehensible, and I wasted half a day until I realized it. It would not be confusing if the flag said "Clear cookies every iteration of the stream group." Very disappointing.

+6
source

Source: https://habr.com/ru/post/1210282/


All Articles