I'm creating custom HTML reports for my selenium framework. Now, when I'm trying to add a screenshot link to my HTML page, I get 'NULL pointer Exception'. Could someone point me where I'm going wrong.
This is my code to write to a HTML file.
public static void writeResults(String SummaryHTMLFile) {
FileOutputStream out; // declare a file o/p object
PrintStream print = null; // declare a print stream object
try {
out = new FileOutputStream(SummaryHTMLFile);
print = new PrintStream(out);
String reportIn = "";
for (int i = 0; i < details.size();i++) {
reportIn = "<html><head><title>Automation Execution Results</title>";
reportIn +="</head><Body>"+
"<p align = center><table border=2 bordercolor=#000000 id=table1 width=900 height=31 bordercolorlight=#000000>"+
"<tr><td COLSPAN = 6 bgcolor = "+h1color+">";
reportIn+= "<p align=center><font color="+fontColor+" size=4 face= Copperplate Gothic Bold>"+"Framwork"+" Automation Execution Results </font><font face= Copperplate Gothic Bold></font> </p>";
reportIn +="</td></tr>"+
"<tr>"+
"<td COLSPAN = 6 bgcolor = "+h1color+">"+
"<p align=justify><b><font color="+fontColor+" size=2 face= Verdana>DATE:"+ currentDate+
"</td></tr>";
reportIn+="<tr bgcolor="+h2color+">"+
"<td><b>Step No</b></td>"+
"<td><b>Step Name</b></td>"+
"<td><b>Description </b></td>"+
"<td><b>Status</b> </td>"+
"<td><b>Screen Shot </b></td>"+
"</tr>";
reportIn+="<tr><td>" + Integer.toString(i+1) +"</td>"+
"<td>" + details.get(i).getStepName() + "</td>"+
"<td>" + details.get(i).getDesc() + "</td>" +
"<td>" + details.get(i).getStrStatus()+ "</td>" +
"<td><a href=" + new File(details.get(i).getResultScreenshot()).toURI().toURL() + ">screenshot</a></td></tr>" +resultPlaceholder;
print.println(reportIn);
print.close();
}
} catch (Exception e) {
System.out.println("Error when writing report file:\n" + e.toString());
}
}
This is the line where I get the Null Pointer exception. If I remove this line, the file gets generated successfully.
"<td><a href=" + new File(details.get(i).getResultScreenshot()).toURI().toURL() + ">screenshot</a></td></tr>" +resultPlaceholder;
EDIT: There is a result class which has getters & setters to retrieve the results.
package com.reporting;
public class Result {
private String result;
private String resultText;
private String stepName;
private String Desc;
private String strStatus;
private String resultScreenshot;
public Result(String resultText,String result) {
this.result = result;
this.resultText = resultText;
}
public Result(String strStepName,String strDescription,String strStatus, String resultScreenshot) {
this.setStepName(strStepName);
this.setDesc(strDescription);
this.setStrStatus(strStatus);
this.setResultScreenshot(resultScreenshot);
//this.resultScreenshot = resultScreenshot;
}
public Result(String strStepName,String strDescription,String strStatus) {
this.setStepName(strStepName);
this.setDesc(strDescription);
this.setStrStatus(strStatus);
}
public void setResult(String result) {
this.result = result;
}
public String getResult() {
return this.result;
}
public void setResultText(String resultText) {
this.resultText = resultText;
}
public String getResultText() {
return this.resultText;
}
public String getStepName() {
return stepName;
}
public void setStepName(String stepName) {
this.stepName = stepName;
}
public String getDesc() {
return Desc;
}
public void setDesc(String desc) {
Desc = desc;
}
public String getStrStatus() {
return strStatus;
}
public void setStrStatus(String strStatus) {
this.strStatus = strStatus;
}
public void setResultScreenshot(String resultScreenshot) {
this.resultScreenshot = resultScreenshot;
}
public String getResultScreenshot() {
return this.resultScreenshot;
}
}