/*
* 将每一步执行的情况写入日志文件
*/
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", "输入邮箱", "
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");
}
}
由测试main函数生成的报告如下: