如何在JMeter中修改/添加到Cookie? [英] How to modify / add to Cookie in JMeter?
问题描述
我是JMeter的新手,需要您的有关如何修改Cookie的帮助.
I'm very new to JMeter and need your help on how to modify a cookie.
这是场景: 我正在测试一个提供有关问题的多个答案的评估/考试网站.当用户进行选择并单击提交"按钮时,页面中的JavaScript会将其答案(例如"Answers = BBAACDA ...")附加到cookie并发出下一个GET请求(而不是POST请求!).
Here is the scenario: I'm testing an assessment/test taking website that offers multiple answers to questions. When a user makes his selections and hits the submit button, the JavaScript in the page appends his answers (e.g., "Answers = BBAACDA...") to the cookie and makes the next GET request (instead of a POST request!).
由于JMeter不执行JavaScript(如其手册中普遍提到的-它不是浏览器),因此无法将答案附加到cookie.结果,我的测试计划无法识别用户交互.
Since, JMeter does not execute JavaScript (as popularly mentioned in its manual - it's not a browser), it cannot append the answers to the cookie. As a result, my test plan fails to recognize user interaction.
如何添加/添加/修改动态Cookie?预先感谢!
How can I add/append/modify a dynamic cookie? Thanks in advance!
-伊什蒂
推荐答案
使用具有groovy的Beanshell预处理器或更好的Jsr223预处理器,并使用此处提到的代码:
Use a Beanshell pre-processor or better a Jsr223 Pre-Processor with groovy and use code mentionned here:
代码:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("<NAME>","<VALUE>","<HOST>","/",false,0);
manager.add(cookie);
这篇关于如何在JMeter中修改/添加到Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!