Reputation: 383
I know how to modify cookies using BeanShell PreProcessor from: How to modify / add to Cookie in JMeter?
Thanks to PMD UBIK-INGENIERIE for the answer!
Now, my question is: how do I modify the cookie value between pages? Let me explain, I've a cookie called 'Answers' that for the first page is empty, i.e., Answers="" (empty), then in second page takes the value Answers="-,-,-,-,-,-"; finally in a third page it takes a longer value Answers="-,A,B,-,C,- ..."
How do I modify the same cookie in different pages? I have seen the CookieManager API: http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/control/CookieManager.html
But can anyone please explain with an example? Thank you!
Upvotes: 2
Views: 2004
Reputation: 168147
As there cannot be 2 cookies having the same name, the CookieManager is smart enough to replace existing cookie with a new value (see removeMatchingCookies(c); // Can't have two matching cookies
line)
So
Requests 2 and 3: Add a Beanshell PreProcessor with the same code like:
import org.apache.jmeter.protocol.http.control.Cookie;
import org.apache.jmeter.protocol.http.control.CookieManager;
CookieManager manager = ctx.getCurrentSampler().getProperty("HTTPSampler.cookie_manager").getObjectValue();
Cookie cookie = new Cookie("Answers", "**VALUE**", sampler.getDomain(), sampler.getPath(), false, System.currentTimeMillis());
manager.add(cookie);
sampler.setCookieManager(manager);
Where **Value**
for Request 2 will be -,-,-,-,-,-
and for Request 3 will be -,A,B,-,C,- ...
For more information on Beanshell scripting and kind of Beanshell cookbook refer to How to use BeanShell: JMeter's favorite built-in component guide.
Upvotes: 2