/*
* 將每一步執(zhí)行的情況寫入日志文件
*/
public void sendStatusToReport(String T_Name,String TC_ID, String Steps,String Data,String verify,String Result)throws Exception{
//先原文件末尾添加內(nèi)容
FileWriter fstream = new FileWriter(filePath, true);
BufferedWriter out = new BufferedWriter(fstream);
//如果該行是測(cè)試用例標(biāo)題行,則顏色設(shè)置為黃色,合并成一行并居中
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>");
//刷新緩沖區(qū)
out.flush();
//關(guān)閉流
out.close();
}else{
//每行顏色設(shè)置成不同
//偶數(shù)行
if(Integer.parseInt(TC_ID)%2==0){
//fail
if(Result.equals("Fail")){
out.write("<tr bgcolor=#FF0000>");//紅色
}else{
out.write("<tr>");
}
//奇數(shù)行
}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();
}
}
//測(cè)試函數(shù)
public static void main(String args[]) throws Exception{
HTMLLOG hl = new HTMLLOG();
hl.generateReport();
hl.sendStatusToReport("致友登錄", "0", "操作步驟", "測(cè)試數(shù)據(jù)", "預(yù)期結(jié)果", "實(shí)際結(jié)果");
hl.sendStatusToReport("", "1", "輸入郵箱", "
kiven@kk.com", "輸入成功", "Pass");
hl.sendStatusToReport("", "2", "輸入密碼", "1", "輸入成功", "Fail");
hl.sendStatusToReport("", "3", "輸入郵箱", "
kicen@kk.com", "輸入成功", "Pass");
hl.sendStatusToReport("", "4", "輸入密碼", "1", "輸入成功", "Pass");
hl.sendStatusToReport("", "5", "干什么", "1", "哦", "Pass");
}
}
由測(cè)試main函數(shù)生成的報(bào)告如下: