";
report(html);
step_already_started = Boolean.TRUE;
}
public static void ask(String task) {
report(formatted_html("ask", task));
}
public static void warn(String task) {
report(formatted_html("warn", task));
}
public static void task(String task) {
report(formatted_html("task", task));
}
public static void action(String action) {
report(formatted_html("action", action));
}
public static void error(String error) {
report(formatted_html("action error", error));
}
public static void info(String info) {
report(formatted_html("info", info));
}
public static void screenshot_taken(File screenshot_file, String file_name) {
try {
FileUtils.copyFile(screenshot_file, new File(report_folder + "/screenshots/" + file_name));
screenshot_taken(file_name);
} catch (IOException e) {
error("Unable to take screenshot : " + Path.TO_SCREENSHOTS + file_name);
}
}
public static void screenshot_taken(String filename) {
String html = StringUtils.EMPTY;
html += "
";
report(html);
}
private static String formatted_html(String id, String text) {
String html = StringUtils.EMPTY;
html += "
" + text + "" + current_date_time() + "
";
return html;
}
private static void report(String text) {
create_file_if_not_exists();
File report_file = new File(report_folder + report_file_name);
try {
System.out.println("\n" + text);
FileUtils.writeStringToFile(report_file, "\n" + text, true);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void create_file_if_not_exists() {
report_folder();
File report_file = new File(report_folder + report_file_name);
if(report_file.exists()) return;
stream_classpath_resource_to_file("/gherkinsaladreport-index.html", report_folder + report_file_name);
stream_classpath_resource_to_file("/style.css", report_folder + "/style.css");
stream_classpath_resource_to_file("/html5shiv.js", report_folder + "/html5shiv.js");
stream_classpath_resource_to_file("/jquery-1.8.0.min.js", report_folder + "/jquery-1.8.0.min.js");
stream_classpath_resource_to_file("/gherkinsaladreport.js", report_folder + "/gherkinsaladreport.js");
}
private static void stream_classpath_resource_to_file(String path_to_classpath_resource, String file_to_write) {
InputStream stream = Report.class.getResourceAsStream(path_to_classpath_resource);
try {
String contents = IOUtils.readFully(stream);
FileUtils.writeStringToFile(new File(file_to_write), contents);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static String current_date_time_file_name() {
return df_for_file.format(new Date());
}
private static String current_date_time() {
return df.format(new Date());
}
private static void report_folder() {
if(report_folder == null) {
File folder = new File(Config.execution_results_storage_location);
if(! folder.exists()) {
folder.mkdirs();
}
String report_folder_name = Config.execution_results_storage_location + "/" + current_date_time_file_name() + "/";
report_folder = new File(report_folder_name);
report_folder.mkdirs();
log.info("REPORTING FOLDER is " + folder.getAbsolutePath());
}
}
}