Session/cookie management in Apache JMeter

烂漫一生 提交于 2019-11-28 05:13:07

Copied from jmeter documentation:

The last element is a HTTP Cookie Manager . A Cookie Manager should be added to all web tests - otherwise JMeter will ignore cookies. By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.

From chapter "4.2.2 Logic Controllers" in http://jmeter.apache.org/usermanual/test_plan.html.

EDIT: I guess you should use http://jmeter.apache.org/usermanual/component_reference.html#Simple_Controller to group your requests together with Cookie Manager.

I think that Andrey's answer cannot help. He quotes that each request will use the same cookies BUT according to jmeter manual:

Each JMeter thread has its own "cookie storage area".

As far as I understand the question, you want each thread to share the same session ID cookie. So it seems to me you need to have two thread groups and execute them consecutively. First thread group (with a single thread that executes once only) should login and save the session cookie value to a global parameter (perhaps you need to use jmeter's scripting capabilities). Then set that cookie in the cookie manager of the second thread group.

Hope that helps.

Try to increase the ramp up time. I ran into the same issue where the ramp up time was about 1 second then I increased it to 3 seconds per thread and it ran fine.

Try this:

Open the user.properties present in the bin folder of JMeter

Edit it and add the following line:

CookieManager.check.cookies=false

Save it and run the script. I hope it will solve your problem.

user2522062

First change your code to:

jmeter.properties
CookieManager.save.cookies=true
CookieManager.name.prefix=mycookie_

Next, add a HTTP cookie manager in the same thread group as your java sampler.

Then in your java sampler add:

JMeterVariables jmv = JMeterContextService.getContext().getVariables();
Iterator<Map.Entry<String,Object>> it = jmv.getIterator();
while(it.hasNext()){
    Map.Entry<String,Object> v = it.next();
    System.out.println("name: " + v.getKey() + " value: " + v.getValue());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!