jmeter中beanshell断言的使用
Posted yingchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jmeter中beanshell断言的使用相关的知识,希望对你有一定的参考价值。
简单使用beanshell的内容,进行测试内容的判断
这里通过断言内容,修改if的条件,达到发送警报邮件的功能
beanshell 代码如下: SampleResult 等效于 prev
log.error(vars.get("ReqStatus"));
int count=Integer.parseInt(vars.get("errorcount").trim());
vars.put("result", SampleResult.getResponseDataAsString());
if (SampleResult.getResponseDataAsString().indexOf("sessionId")!= -1)
{
String code =SampleResult.getResponseCode();
String msg = SampleResult.getResponseMessage();
String data = SampleResult.getResponseDataAsString();
log.error("------return code "+ code);
vars.put("responsecode", code);
vars.put("responsedata",data);
vars.put("responsemsg",msg);
count = count + 1;
vars.put("errorcount", count.toString());
if((count%1)==0)
{
vars.put("sendmail","yes");
}
else{
vars.put("sendmail","no");
}
SampleResult.setSuccessful(true);
}
else
{
String code =SampleResult.getResponseCode();
String msg = SampleResult.getResponseMessage();
String data = SampleResult.getResponseDataAsString();
log.error("------return code "+ code);
vars.put("responsecode", code);
vars.put("responsedata",data);
vars.put("responsemsg",msg);
SampleResult.setSuccessful(true);
}
设置系统的变量如下:
附件顺便加上beanshell的用法汇总:
http://www.cnblogs.com/xxyBlogs/p/5966194.html
以上是关于jmeter中beanshell断言的使用的主要内容,如果未能解决你的问题,请参考以下文章