首页 > 代码库 > jmeter中beanshell断言的使用
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 = http://www.mamicode.com/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 = http://www.mamicode.com/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断言的使用