09JMETER之BeanShell后置处理器将返回信息写入文件中

 BeanShell后置处理器将返回信息写入文件中

 具体代码:

public static void execParam() 
{
String res = vars.get("response");
String openDate = "${RUN_DATE_1}";
String retCode = "${retCode}";
String filename = "./../result/response${__time(yyyyMMdd,)}.csv";
String han = "${__samplerName()}";
URL url = prev.getURL();
FileWriter writer;

         try {
            writer = new FileWriter(filename,true);
            PrintWriter pw = new PrintWriter(writer);
            
       if(retCode!="000000"){
            pw.write("日期:"+openDate+"\r\n"+han+"\r\n"+url+"\r\n"+"错误信息:"+res+"\r\n"+"\r\n");
            pw.write("==========================================================================="+"\r\n"+"\r\n");
          }
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
}
        execParam();

posted @ 2022-10-27 22:01  谷灵精怪  阅读(301)  评论(0编辑  收藏  举报