jmeter中mail reader sampler邮件层级多,正则表达式提取器(reg
问题描述: 1、jmeter通过“MailReader Sampler”连接服务器,将发送到邮箱的包含注册验证码邮件下载到jmeter中,在邮件中提取验证码,进行后续注册验证,即:
2、使用“正则表达式提取器”进行验证码提取:
结果无法取到验证码; 3、使用“BeanShellPostProcessor”解决:
在“script”中编写代码: Stringresponse =prev.getSubResults()[0].getSubResults()[0].getSubResults()[0].getResponseDataAsString(); vars.put("response",response.substring(70,76));
说明: “prev”- is a shorthand for previous sampleresult. It returns Mail Reader Sampler first getSubResults()[0] - stands forMessage 1. second getSubResults()[0] - upper Part 0 third getSubResults[0] - Part 0 which I'mlooking for vars.put("response",76)) -stores message content as "response" variable. You can apply assertionon JMeter Variable as well. FROM:http://jmeter.512774.n5.nabble.com/Question-about-mail-reader-sampler-td5721461.html 在之后的线程中引用参数:${response},即可取到验证码; response.substring(70,76):这是邮件正文开头到验证码前字符数量统计,总计69个,包括空格,符号: “<h3>尊敬的用户您好:</h3><br><PRE>	您于2016年11月09日 15时42分47秒提交的账户安全邮箱验证,验证码为:733486” 上面标红的字符即为69个,汉字也按一个字符进行计算
参考:http://jmeter.512774.n5.nabble.com/Question-about-mail-reader-sampler-td5721461.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |