全网最牛最全的jmeter跨线程组获取cookie或jmeter线程组共享cookie

一、Jmeter版本

此次示例采用的是apache-jmeter-5.2.1版本

二、设置配置文件使Cookie管理器保存cookie信息。

修改apache-jmeter-5.2.1/bin/jmeter.properties文件,把CookieManager.save.cookies设置为true,并去掉前面的注释#号,如下图所示:

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

修改完成后保存,退出,并重启jmeter。

 点我·领取全套自动化测试资料icon-default.png?t=M4ADhttps://mp.weixin.qq.com/s/Wl_Hrfh6terL_FyegcCW2w

三、在调试取样器和请求中查看具体的cookie信息

在线程组中添加HTTP Cookie 管理器,运行测试计划后,HTTP Cookie 管理器会自动存储这些cookie,变量名称为COOKIE_XXX,XXX对应的是cookie的名称,可以添加【调试取样器】来查看自动存储的cookie值,如下图所示:

下图中有两个cookie值分别为:COOKIE_z92_lastvisit何COOKIE_z92_visitor

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

这里要注意一下,有时候你会发现这里的cookie不全,所以比较保险的做法下,进入第一个请求中查看request body中的cookie值。如下图所示:下图中有三个cookie值分别为:z92_visitor和z92_lastvisit以及csrf_token三个值。这里比前者多了一个cookie值。

四、设置cookie为全局变量

在BeanShell后置处理程序中使用__setProperty()函数将COOKIE_XXXX设置为全局变量。如下图所示:

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

https://mp.weixin.qq.com/s/Wl_Hrfh6terL_FyegcCW2wicon-default.png?t=M4ADhttp://点我免费领取全套自动化测试资料

 

五、获取并存储Cookie

在HTTP Cookie管理器中通过__P()函数获取全局变量Cookie,并加入到Cookie管理器中。注意名称和在请求中的cookie名称保持一致。如下图的z92_visitor和z92_lastvisit以及csrf_token三个值。

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

六、调用登录接口测试验证cookie是否可以跨线程共享

(1) 同一个线程中调用登录接口:

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

结果如下:提示state为success,表示登录成功!

ca38ab082e42439a9e760e0dcb40fa16.gifwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==编辑

(2) 不同的线程中调用登录接口

93ba07a738974461ac936ee6b4013207.gifwAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==编辑

结果如下:提示state为success,表示登录成功!

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==编辑

OK大功告成,线程1和线程2实现cookie共享成功!

   

 

 文章到这里就结束了,各位铁汁如果有什么觉得不对的可以发在评论区咱们来讨论哈,
听说关注我并三连的铁汁都已经升职加薪暴富了哦!!!! 

Jmeter各个版本下载地址(包括所有版本) [ ] apache-jmeter-2.10.tgz 2013-10-20 16:32 28M [TXT] apache-jmeter-2.10.tgz.asc 2013-10-20 16:32 836 [ ] apache-jmeter-2.10.tgz.md5 2013-10-20 16:32 56 [ ] apache-jmeter-2.10.tgz.sha 2013-10-20 16:32 64 [ ] apache-jmeter-2.10.zip 2013-10-20 16:32 30M [TXT] apache-jmeter-2.10.zip.asc 2013-10-20 16:32 836 [ ] apache-jmeter-2.10.zip.md5 2013-10-20 16:32 56 [ ] apache-jmeter-2.10.zip.sha 2013-10-20 16:32 64 [ ] apache-jmeter-2.11.tgz 2014-01-04 13:30 28M [TXT] apache-jmeter-2.11.tgz.asc 2014-01-04 13:30 836 [ ] apache-jmeter-2.11.tgz.md5 2014-01-04 13:30 56 [ ] apache-jmeter-2.11.tgz.sha 2014-01-04 13:30 64 [ ] apache-jmeter-2.11.zip 2014-01-04 13:30 30M [TXT] apache-jmeter-2.11.zip.asc 2014-01-04 13:30 836 [ ] apache-jmeter-2.11.zip.md5 2014-01-04 13:30 56 [ ] apache-jmeter-2.11.zip.sha 2014-01-04 13:30 64 [ ] apache-jmeter-2.12.tgz 2014-11-09 10:42 30M [TXT] apache-jmeter-2.12.tgz.asc 2014-11-09 10:42 836 [ ] apache-jmeter-2.12.tgz.md5 2014-11-09 10:42 56 [ ] apache-jmeter-2.12.tgz.sha 2014-11-09 10:42 64 [ ] apache-jmeter-2.12.zip 2014-11-09 10:42 32M [TXT] apache-jmeter-2.12.zip.asc 2014-11-09 10:42 836 [ ] apache-jmeter-2.12.zip.md5 2014-11-09 10:42 56 [ ] apache-jmeter-2.12.zip.sha 2014-11-09 10:42 64 [ ] apache-jmeter-2.13.tgz 2015-03-13 19:30 34M [TXT] apache-jmeter-2.13.tgz.asc 2015-03-13 19:30 819 [ ] apache-jmeter-2.13.tgz.md5 2015-03-13 19:30 56 [ ] apache-jmeter-2.13.tgz.sha 2015-03-13 19:30 64 [ ] apache-jmeter-2.13.zip 2015-03-13 19:30 36M [TXT] apache-jmeter-2.13.zip.asc 2015-03-13 19:30 819 [ ] apache-jmeter-2.13.zip.md5 2015-03-13 19:30 56 [ ] apache-jmeter-2.13.zip.sha 2015-03-13 19:30 64 [ ] apache-jmeter-2.6.tgz 2012-02-01 19:59 21M [TXT] apache-jmeter-2.6.tgz.asc 2012-02-01 19:59 836 [ ] apache-jmeter-2.6.tgz.md5 2012-02-01 19:59 55 [ ] apache-jmeter-2.6.tgz.sha 2012-02-01 19:59 63 [ ] apache-jmeter-2.6.zip 2012-02-01 19:59 23M [TXT] apache-jmeter-2.6.zip.asc 2012-02-01 19:59 836 [ ] apache-jmeter-2.6.zip.md5 2012-02-01 19:59 55 [ ] apache-jmeter-2.6.zip.sha 2012-02-01 19:59 63 [ ] apache-jmeter-2.7.tgz 2012-05-27 21:08 22M [TXT] apache-jmeter-2.7.tgz.asc 2012-05-27 21:08 836 [ ] apache-jmeter-2.7.tgz.md5 2012-05-27 21:08 55 [ ] apache-jmeter-2.7.tgz.sha 2012-05-27 21:08 63 [ ] apache-jmeter-2.7.zip 2012-05-27 21:08 24M [TXT] apache-jmeter-2.7.zip.asc 2012-05-27 21:08 836 [ ] apache-jmeter-2.7.zip.md5 2012-05-27 21:08 55 [ ] apache-jmeter-2.7.zip.sha 2012-05-27 21:08 63 [ ] apache-jmeter-2.8.tgz 2012-11-26 01:30 23M [TXT] apache-jmeter-2.8.tgz.asc 2012-11-26 01:30 836 [ ] apache-jmeter-2.8.tgz.md5 2012-11-26 01:30 55 [ ] apache-jmeter-2.8.tgz.sha 2012-11-26 01:30 63 [ ] apache-jmeter-2.8.zip 2012-11-26 01:30 25M [TXT] apache-jmeter-2.8.zip.asc 2012-11-26 01:30 836 [ ] apache-jmeter-2.8.zip.md5 2012-11-26 01:30 55 [ ] apache-jmeter-2.8.zip.sha 2012-11-26 01:30 63 [ ] apache-jmeter-2.9.tgz 2013-01-27 17:28 25M [TXT] apache-jmeter-2.9.tgz.asc 2013-01-27 17:28 836 [ ] apache-jmeter-2.9.tgz.md5 2013-01-27 17:28 55 [ ] apache-jmeter-2.9.tgz.sha 2013-01-27 17:28 63 [ ] apache-jmeter-2.9.zip 2013-01-27 17:28 27M [TXT] apache-jmeter-2.9.zip.asc 2013-01-27 17:28 836 [ ] apache-jmeter-2.9.zip.md5 2013-01-27 17:28 55 [ ] apache-jmeter-2.9.zip.sha 2013-01-27 17:28 63 [ ] apache-jmeter-3.0.tgz 2016-05-17 18:34 43M [TXT] apache-jmeter-3.0.tgz.asc 2016-05-17 18:34 819 [ ] apache-jmeter-3.0.tgz.md5 2016-05-17 18:34 55 [ ] apache-jmeter-3.0.tgz.sha 2016-05-17 18:34 63 [ ] apache-jmeter-3.0.zip 2016-05-17 18:34 46M [TXT] apache-jmeter-3.0.zip.asc 2016-05-17 18:34 819 [ ] apache-jmeter-3.0.zip.md5 2016-05-17 18:34 55 [ ] apache-jmeter-3.0.zip.sha 2016-05-17 18:34 63 [ ] apache-jmeter-3.1.tgz 2016-11-19 22:49 45M [TXT] apache-jmeter-3.1.tgz.asc 2016-11-19 22:49 801 [ ] apache-jmeter-3.1.tgz.md5 2016-11-19 22:49 55 [ ] apache-jmeter-3.1.tgz.sha 2016-11-19 22:49 63 [ ] apache-jmeter-3.1.zip 2016-11-19 22:49 48M [TXT] apache-jmeter-3.1.zip.asc 2016-11-19 22:49 801 [ ] apache-jmeter-3.1.zip.md5 2016-11-19 22:49 55 [ ] apache-jmeter-3.1.zip.sha 2016-11-19 22:49 63 [ ] apache-jmeter-3.2.tgz 2017-04-13 18:07 48M [TXT] apache-jmeter-3.2.tgz.asc 2017-04-13 18:07 833 [ ] apache-jmeter-3.2.tgz.md5 2017-04-13 18:07 55 [ ] apache-jmeter-3.2.tgz.sha 2017-04-13 18:07 63 [ ] apache-jmeter-3.2.zip 2017-04-13 18:07 51M [TXT] apache-jmeter-3.2.zip.asc 2017-04-13 18:07 833 [ ] apache-jmeter-3.2.zip.md5 2017-04-13 18:07 55 [ ] apache-jmeter-3.2.zip.sha 2017-04-13 18:07 63 [ ] apache-jmeter-3.3.tgz 2017-09-21 06:27 49M [TXT] apache-jmeter-3.3.tgz.asc 2017-09-21 06:27 833 [ ] apache-jmeter-3.3.tgz.md5 2017-09-21 06:27 55 [ ] apache-jmeter-3.3.tgz.sha512 2017-09-21 06:27 151 [ ] apache-jmeter-3.3.zip 2017-09-21 06:27 52M [TXT] apache-jmeter-3.3.zip.asc 2017-09-21 06:27 833 [ ] apache-jmeter-3.3.zip.md5 2017-09-21 06:27 55 [ ] apache-jmeter-3.3.zip.sha512 2017-09-21 06:27 151 [ ] jakarta-jmeter-2.5.1.tgz 2011-10-03 20:43 18M [TXT] jakarta-jmeter-2.5.1.tgz.asc 2011-10-03 20:43 836 [ ] jakarta-jmeter-2.5.1.tgz.md5 2011-10-03 20:43 58 [ ] jakarta-jmeter-2.5.1.tgz.sha 2011-10-03 20:43 66 [ ] jakarta-jmeter-2.5.1.zip 2011-10-03 20:43 20M [TXT] jakarta-jmeter-2.5.1.zip.asc 2011-10-03 20:43 836 [ ] jakarta-jmeter-2.5.1.zip.md5 2011-10-03 20:43 58 [ ] jakarta-jmeter-2.5.1.zip.sha 2011-10-03 20:43 66 ........................................
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值