int time = prev.getTime(); //获取接口响应时间
if(time > 3000){ //判断如果响应时间大于3秒则输出相关内容
FileWriter fstream = new FileWriter("/home/PerfSpace/04project/errLog/TimeLong.txt",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("=================================开始===================================");
out.write(System.getProperty("line.separator"));
out.write("接口响应时间(ms):");
out.write(prev.getTime().toString()); //将int类型响应时间转成string并输出
out.write(System.getProperty("line.separator"));
out.write("请求头信息是:");
out.write(prev.getRequestHeaders()); //(我测试的流水号在header里)输出响应头信息,正常可以输出流水号、响应报文、参数化的某个变量等,
out.write(System.getProperty("line.separator"));
out.write("=================================结束===================================");
out.write(System.getProperty("line.separator"));
out.close();
fstream.close();
}
String resp = prev.getResponseDataAsString();
String code = prev.getResponseCode();
String reqDate = prev.getSamplerData();
String time="${__time(yyyy-MM-dd HH:mm:ss,)}";
if ("200".equals(""+code) == false){ //判断响应是否包含200;也可以判断字符串:if((response.contains("\"bindStatus\":\"Y\"")))
Failure = true;
String[] ss = resp.split("\n");
FailureMessage = ss[0];
FileWriter fstream = new FileWriter("/home/PerfSpace/03project/errLog/ATH文件下载Error.txt",true); //打开要写入文件的路径和名称
BufferedWriter out = new BufferedWriter(fstream);
out.write("===================================began================================");
out.write("请求时间:"+vars.get("time"), "请求报文:"+reqDate);
out.write(System.getProperty("line.separator")); //换行符,避免内容打印到一行,不方便查看
out.write("响应时间:"+vars.get("time"),"接口响应:"+FailureMessage);
out.write(System.getProperty("line.separator"));
out.write("===================================over================================");
out.write(System.getProperty("line.separator"));
out.close();
fstream.close();
}
else {
Failure = false;
}