如何在 JMeter 中修改/添加到 Cookie? [英] How to modify / add to Cookie in JMeter?

查看:27
本文介绍了如何在 JMeter 中修改/添加到 Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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!

--Ishti

推荐答案

使用 Beanshell 预处理器或更好的 Jsr223 预处理器和 groovy 并使用这里提到的代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆