您的位置:软件测试 > 开源软件测试 > 开源功能测试工具 > Selenium
Selenium之报告生成
作者:网络转载 发布时间:[ 2016/6/23 15:08:53 ] 推荐标签:Selenium 函数

  一般我们写的脚本可能覆盖了较多的测试项,而且可能持续运行了一段时间,本文将教各位实现在执行完自动化脚本后自动生成一份美化报告
  自动生成报告类
  话不多说,直接上代码,代码中会有详细注释:
  程序清单1:
  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:;"
  + " 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:;"
  + " 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:;"
  + " 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= border=0 cellpadding=2 cellspacing=2>");
  out.write("<tbody>");
  out.write("<tr>");
  out.write("<td>");
  out.write("<table width= 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(); 
  }

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd