如何在通常通过 Javascript 设置的 JMeter 中设置 cookie? [英] How to set cookie in JMeter that is usually set via Javascript?
问题描述
我正在测试一个网络应用程序.
在主页面的导航菜单中,当点击一个节点时,会调用一个javascript函数.我查了一下这个函数,页面会在重定向到目标页面之前设置document.cookie="current_moduleId=xxxx;path=/"
.
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.
那么如何在 JMeter 中为每个请求设置 cookie?
So how can I set cookie in JMeter for every request?
推荐答案
创建以下锅:
在 BeanShell 预处理器中,输入:
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);
请注意,使用 JSR223 PreProcessor + Groovy + Caching 会更好地提高性能
Note that using JSR223 PreProcessor + Groovy + Caching will be better for performances
这篇关于如何在通常通过 Javascript 设置的 JMeter 中设置 cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!