admin管理员组

文章数量:1353278

I am testing a web application.
In the navigation menu of the main page, when a node is clicked, a javascript function will be called. I look up this function, the page will set document.cookie="current_moduleId=xxxx;path=/" before redirect to the target page.

So how can I set cookie in JMeter for every request?

I am testing a web application.
In the navigation menu of the main page, when a node is clicked, a javascript function will be called. I look up this function, the page will set document.cookie="current_moduleId=xxxx;path=/" before redirect to the target page.

So how can I set cookie in JMeter for every request?

Share Improve this question edited Dec 4, 2012 at 13:32 Andrei Botalov 21.1k11 gold badges90 silver badges124 bronze badges asked Dec 3, 2012 at 9:29 BugdailyBugdaily 1771 gold badge2 silver badges10 bronze badges 1
  • See jmeter.512774.n5.nabble./…. I wasn't able to get it to work – Andrei Botalov Commented Dec 4, 2012 at 10:13
Add a ment  | 

2 Answers 2

Reset to default 7

Create the following pan:

In BeanShell pre processor, put :

  import org.apache.jmeter.protocol.http.control.CookieManager;
  import org.apache.jmeter.protocol.http.control.Cookie;
  CookieManager manager = sampler.getCookieManager();
  Cookie cookie = new Cookie("toto","titi","localhost","/",false,0);
  manager.add(cookie); 

Note that using JSR223 PreProcessor + Groovy + Caching will be better for performances

For people who e across this in future, I had to use 0 or -1 for the expiry time of the cookie:

Cookie cookie = new Cookie("toto","titi","localhost","/",false,-1);

Any positive integers seemed to not set the cookie

本文标签: How to set cookie in JMeter that is usually set via JavascriptStack Overflow