Placed the reports have overrided all the results我想在带有结果的表格中打印,但是当我打印时,它覆盖了结果,并且只打印了一行
从其他类文件传递值以打印结果
我尝试使用Buffered writer编写代码
public void createTestSummaryHTMLTable(String sample,String samp[le,String sample,String passedText,String status) throws IOException {
File file=new File("C:\\AutomationResults\\Forms\\",foldername);
if(!file.exists()){
file.mkdir();}
final String FILE_PATH =(file+"/"+formname);
//final String FILE_PATH = "C:\\AutomationResults\\Forms\\"+formname;
final String FILE_EXTENSION = "html";
DateFormat df = new SimpleDateFormat("yyyyMMdd"); // add S if you need milliseconds
String filename = FILE_PATH + "_"+ df.format(new Date()) + "." + FILE_EXTENSION;
File file2 = new File(filename);
// if file doesnt exists, then create it
if (!file2.exists()) {
file2.createNewFile();
}
BufferedWriter html = new BufferedWriter(new FileWriter(file2));
html.write("<html><body bgcolor='#E6E6FA'><table border=1 cellpadding=0>");
html.write("<title>Automation Summary report </title>");
html.write("<br>");
html.write("<center><strong><em>Batch report heading</em></strong>");
html.write("<span style ='float; right;position:relative;right:30px;font weight:bold'>"+new Date().toString()+"</span>");
html.write("<tr>");
addlabel1(html,"Test Step Name");
addlabel1(html,"Test Step Description");
addlabel1(html,"Status");
addlabel1(html,"Screenshot");
html.write("</tr>");
html.write("<tr>");
html.newLine();
addlabel(html,sample);
addlabel(html,sample);
String status1 = "Passed";
if (status1.equals(status))
{
html.write("<td width='20'style='color:#00F00;font-weight:bold;text-align:center'>"+status+"</td>");
} else {
html.write("<td width='20'style='color:#A52A2A;font-weight:bold;text-align:center'>"+status+"</td>");
}
addlabel(html,"Screenshot");
html.write("</tr>");
html.write("</table></body></html>");
html.close();
}
答案 0 :(得分:0)
哦,我想我猜到了你的问题。写入的文件只有一行。
那是因为写只写您所提供的内容。您需要在所有字符串的末尾添加\ n。
或者,使用Printwriter的println方法输出到您的文件。
答案 1 :(得分:0)
您可以尝试向FileWriter
添加一个布尔参数,该布尔参数有助于指定是应追加还是覆盖现有内容。如果传递true,它将打开文件以追加模式进行写入。
请更改此行:
BufferedWriter html = new BufferedWriter(new FileWriter(file2));
对此:
BufferedWriter html = new BufferedWriter(new FileWriter(file2, true));
答案 2 :(得分:0)
实际结果
header is displaying for every row i dont need the header to display for all the rows结果正在得到 预期结果是
标题应该只显示一次