JMeter在同一迭代中的HTTP请求之后清除cookie

时间:2019-12-09 04:07:21

标签: cookies jmeter iteration clear

某些步骤后,我正在努力清除Cookie。这就是我的示例测试计划中的内容 enter image description here enter image description here enter image description here enter image description here 我从CSV文件中获取数据,然后有多个Cookie-这是我需要为CSV中的每一行传递的位置ID。我尝试使用带有选项的Cookie Manager来清除迭代,该迭代对于CSV中的下一行效果很好,但不能遍历用户定义变量中定义的cookie列表。我看着这个 article 我尝试将此代码添加到与HTTP请求相同的级别,但是会收到错误

2 个答案:

答案 0 :(得分:0)

sampler.getCookieManager().clear() function应该为您解决问题

演示:

enter image description here

鉴于您收到的NPE很可能是HTTP Cookie Manager配置出现问题的原因,您可以尝试enabling debug logging for it来查看JMeter是否对任何内容“抱怨”,如果可以,请修复-相应地配置HTTP Cookie Manager。

为了获取HTTP Cookie管理器的扩展调试信息,将下一行添加到 log4j2.xml 文件:

<Logger name="org.apache.jmeter.protocol.http.control.CookieManager" level="debug" />

需要重新启动JMeter才能拾取该属性。

答案 1 :(得分:0)

任何人都在寻找答案,就我而言,这很简单。我只需要添加空白的Cookie管理器

Header Cookies

以前,我已经用引起一些问题的值填充了这些值。 现在,我使用此代码添加了JSR223预处理器,并且效果很好

import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
Cookie newCookie;
CookieManager manager = sampler.getCookieManager();
location = vars.get("locationID_"+ vars.get("counter"))
Cookie myCookie = new Cookie("location_ID", location, google.com"/",false , 0);
manager.add(myCookie);