自訂報告,用Java寫一個html檔案

來源:互聯網
上載者:User

標籤:stream   cep   class   not   one   static   pac   ref   until   

因為testng不滿足我們的展示,所以我們會自己定義一個報告,實施步驟是,把靜態頁面做好後,放在Java項目中,其實和產生一個記錄檔類似,只是該了尾碼,Java中需要使用到PrintStream,案例如下,我在靜態頁面中製作的靜態網頁

在代碼中實現如下,就是把所有內容搬移過來

package until;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.PrintStream;public class tables { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); PrintStream printStream = null ; try { printStream= new PrintStream(new FileOutputStream("report.html"));//路徑預設在項目根目錄下} catch (FileNotFoundException e) {e.printStackTrace();} sb.append("<html>"); sb.append("<head>"); sb.append("<title>測試報告的樣式</title>"); sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");     //樣式內容sb.append("<style type=\"text/css\">"); sb.append(".tablename table th {background:#8FBC8F}");sb.append(".tablename table tr{ background:#FAEBD7;text-align:center}");sb.append("</style></head>"); //樣式結尾//主體部分一個divsb.append("<div class=\"tablename\">"); //一個tablesb.append("<table width=\"500\"  height=\"100\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse;\">");sb.append("<th>用例集/測試方法</th><th>總計</th><th>通過</th><th>失敗</th><th>通過率</th><th>詳細</th><tr>");sb.append("<td>test集合</td><td>10</td><td>8</td><td>2</td><td>80%</td> <td>點我查看詳情</td></tr>");sb.append("<th>測試方法</th><th>測試項</th><th>測試模組</th><th>測試描述</th><th>驗證點</th>");sb.append("<tr><td>"+12333+"</td><td>變數2</td><td>變數3</td><td>變數4</td><td>變數5</td>");sb.append("</tr></table>");//table與html結尾sb.append("</div></body></html>");      printStream.println(sb.toString()); } }

執行完成後,產生的報告,

雙擊開啟查看樣式

自訂報告,用Java寫一個html檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.