一般的BeanShell Assertion断言响应

1、添加BeanShell Assertion断言

一般的BeanShell Assertion断言响应_第1张图片

 2、进行响应结果判断,及失败时断言消息提醒

一般的BeanShell Assertion断言响应_第2张图片

3、断言里面的java代码展示

String assertStr=vars.get("nowAssert");
String name=vars.get("nowName");

byte[] rpData = (byte[])ResponseData;
String returnStr=new String(rpData);
if("200".equals(ResponseCode) && "OK".equals(ResponseMessage) && returnStr.contains(assertStr)){
	vars.put("result","通过");	
	vars.put("errPath","通过不保存响应文件");	
}else{
	Failure = true;
	FailureMessage = "包含断言("+assertStr+")失败";
	vars.put("result","失败");
	String filePath="E:/tools/apache-jmeter-4.0/workspace/errLog/"+name+".html";
	try{
		File file = new File(filePath);
		if(!file.exists()){
			file.createNewFile();
		}
		FileOutputStream fos = new FileOutputStream(file.getAbsoluteFile(),false);
		fos.write(rpData);
		fos.close();
	}catch(IOException e){
		e.printStackTrace();
		fos.close();
	}
	vars.put("errPath",filePath);
}

 

你可能感兴趣的:(jmeter)