보고서 생성

8562 단어 낳다
일반적으로 우리가 쓴 스크립트는 비교적 많은 테스트 항목을 덮어쓰고 일정 시간 동안 지속될 수 있습니다. 본고는 자동화 스크립트를 실행한 후에 자동으로 미화 보고서를 생성하는 것을 가르쳐 드리겠습니다.
package ts.dw.logic;
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
 
public class HTMLLOG {
	static GregorianCalendar time = new GregorianCalendar();	
	public static String filePath = "";
	public static String reportGenerated = "";
 
	//  HTML
	public void generateReport()throws Exception{
	    reportGenerated="true";  
	    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
	    Calendar cal = Calendar.getInstance();
	    String timeStamp=dateFormat.format(cal.getTime());
	    //String path = System.getProperty("user.dir")+"log";
	    filePath = "log\\"+"Regression_Result-"+"-"+timeStamp+".html";
	    FileWriter fstream = new FileWriter(filePath);
	    System.out.println("Report's FileName: "+filePath);
	    BufferedWriter out = new BufferedWriter(fstream);
	    out.write("html");
	    out.write("head");
	    //out.write("meta http-equiv='Content-Type' content='text/html; charset=utf-8'");
	    out.write("style type='text/css' " 
	    	  + " #summary" 
	  	      + " {"
	  	      + " font-family:\"Trebuchet MS\", Arial, Helvetica, sans-serif;"
	  	      + " width:100%;"
	  	      + " border-collapse:collapse;"
	  	      + " }"
	  	      + " #summary td, #summary th"
	  	      + " {"
	  	      + " font-size:0.8em;"
	  	      + " border:1px solid #98bf21;"
	  	      + " padding:3px 7px 2px 7px;"
	  	      + " }"
	  	      + " #summary th"
	  	      + " {"
	  	      + " font-size:1.0em;"
	  	      + " text-align:left;"
	  	      + " padding-top:5px;"
	  	      + " padding-bottom:4px;"
	  	      + " background-color:#A7C942;"
	  	      + " color:#ffffff;"
	  	      + " }"
 
	  	      + " #componentWiseSummary" 
		      + " {"
		      + " font-family:\"Trebuchet MS\", Arial, Helvetica, sans-serif;"
		      + " width:100%;"
		      + " border-collapse:collapse;"
		      + " }"
		      + " #summary td, #summary th"
		      + " {"
		      + " font-size:0.8em;"
		      + " border:1px solid #98bf21;"
		      + " padding:3px 7px 2px 7px;"
		      + " }"
		      + " #summary th"
		      + " {"
		      + " font-size:1.0em;"
		      + " text-align:left;"
		      + " padding-top:5px;"
		      + " padding-bottom:4px;"
		      + " background-color:#A7C942;"
		      + " color:#ffffff;"
		      + " }"
 
			  + " #customers" 
		      + " {"
		      + " font-family:\"Trebuchet MS\", Arial, Helvetica, sans-serif;"
		      + " width:100%;"
		      + " border-collapse:collapse;"
		      + " }"
		      + " #customers td, #customers th"
		      + " {"
		      + " font-size:0.8em;"
		      + " border:1px solid #98bf21;"
		      + " padding:3px 7px 2px 7px;"
		      + " }"
		      + " #customers th"
		      + " {"
		      + " font-size:1.1em;"
		      + " text-align:left;"
		      + " padding-top:5px;"
		      + " padding-bottom:4px;"
		      + " background-color:#A7C942;"
		      + " color:#ffffff;"
		      + " }"
		      + " #customers tr.alt td"
		      + " {"
		      + " color:#000000;"
		      + " background-color:#EAF2D3;"
		      + " }"
	          + " </style>");
	    out.write("head");
 
	    out.write("body text-align:center");
 
	    out.write("table width=100% border=0 cellpadding=2 cellspacing=2");
	    out.write("tbody");
	    out.write("tr");
	    out.write("td");
	    out.write("table width=100% border=0 cellpadding=2 cellspacing=2");
	    out.write("tbody");
	    out.write("tr");
	    out.write("td align=center p class=title h1        -By Kiven h1 p td tr");
	    out.write("tr" + "tbody" + "table" + "br");
 
	    /**
	     * Creating tables in HTML for Test Status
	     */    
	    out.write("table id=\"customers\"");
	    out.write("tr");
	    out.write("th Test Case Name</th>");
	    out.write("th Test Case ID</th>");
	    out.write("th Test Name and Steps</th>");
	    out.write("th Test Data th");
	    out.write("th Expected Result th");
	    out.write("th Actual Result th");
	    out.write("tr");
	    out.write("body");
	    out.write("html");
	    out.flush();
	    out.close();  
	}
 
	/*
	 *                
	 */
	public void sendStatusToReport(String T_Name,String TC_ID, String Steps,String Data,String verify,String Result)throws Exception{
 
	    //          
	    FileWriter fstream = new FileWriter(filePath, true);
	    BufferedWriter out = new BufferedWriter(fstream);
 
	    //            ,        ,        
	    if(Integer.parseInt(TC_ID)==0){
	    	out.write("tr bgcolor=#FFFF00 align='center'");
	    	out.write("td  colspan='6' b" + T_Name + "b td");
	    	out.write("tr");
                //     
	        out.flush();
                //   
	        out.close();
	    }else{
	    	//         
		    //   
		    if(Integer.parseInt(TC_ID)%2==0){
		    	//fail
		    	if(Result.equals("Fail")){
			    	out.write("tr bgcolor=#FF0000");//  
			    }else{
			    	out.write("tr");
			    }
		    	//   
		    }else{
		    	//fail
		    	if(Result.equals("Fail")){
			    	out.write("tr bgcolor=#FF0000");//red:bgcolor=#FF0000
			    }else{
			    	out.write("tr bgcolor=#EAF2D3");//   
			    }
		    }
	    	    out.write("td b" + T_Name + "b td");
		    out.write("td b" + TC_ID + "b td");
		    out.write("td b" + Steps + "b td");
		    out.write("td b" + Data + "b td");
		    out.write("td b" + verify + "b td");
		    out.write("td b" + Result + "b td");
		    out.write("tr");
		    out.flush();
		    out.close();
	    }
 
 
	}
 
	//    
	public static void main(String args[]) throws Exception{
		HTMLLOG hl = new HTMLLOG();
		hl.generateReport();
		hl.sendStatusToReport("    ", "0", "    ", "    ", "    ", "    ");
		hl.sendStatusToReport("", "1", "    ", "[email protected]", "    ", "Pass");
		hl.sendStatusToReport("", "2", "    ", "1", "    ", "Fail");
		hl.sendStatusToReport("", "3", "    ", "[email protected]", "    ", "Pass");
		hl.sendStatusToReport("", "4", "    ", "1", "    ", "Pass");
		hl.sendStatusToReport("", "5", "   ", "1", " ", "Pass");
	}
}

좋은 웹페이지 즐겨찾기