Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,68 @@ public String getFileName() {
return fileName;
}

@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDir) {
try (PrintWriter writer = createWriter(outputDir)) {
this.writer = writer;

for (ISuite suite : suites)
suiteResults.add(new SuiteResult(suite));

writeDocumentStart();
writeHead();
writeBody();
writeDocumentEnd();
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
try {
writer = createWriter(outputDirectory);
} catch (IOException e) {
logger.error("Error creating TestNG report", e);
logger.error("Unable to create output file", e);
return;
}

// --- Prepare filename details ---
String lang = ConfigManager.getValueForKey("loginlang");
if (lang == null || lang.isEmpty())
lang = "eng";

String date = java.time.LocalDateTime.now()
.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm"));

String env = "base-run";
try {
String envUser = ConfigManager.getiam_apienvuser();
if (envUser != null && !envUser.isEmpty())
env = envUser.replaceAll(".*?\\.([^\\.]+\\.[^\\.]+).*", "$1");
} catch (Exception ignored) {
}

int total = totalPassedTests + totalSkippedTests + totalFailedTests;

String newName = String.format("ADMINUI-%s-%s-%s-report_T-%d_P-%d_S-%d_F-%d.html", env, lang, date, total,
totalPassedTests, totalSkippedTests, totalFailedTests);

// --- Rename file ---
File oldFile = new File(outputDir, fileName);
File newFile = new File(outputDir, newName);
if (oldFile.exists()) {
if (newFile.exists()) {
logger.warn("Target report file already exists: " + newName);
} else if (oldFile.renameTo(newFile)) {
logger.info("Report renamed to: " + newName);
for (ISuite suite : suites) {
suiteResults.add(new SuiteResult(suite));
}
writeDocumentStart();
writeHead();
writeBody();
writeDocumentEnd();
writer.close();

int totalTestCases = totalPassedTests + totalSkippedTests + totalFailedTests;
String oldString = System.getProperty("emailable.report2.name", fileName);
String temp = "-report_T-" + totalTestCases + "_P-" + totalPassedTests + "_S-" + totalSkippedTests + "_F-"
+ totalFailedTests;
String newString = oldString.replace("-report", temp);

String reportDir = outputDirectory; // or System.getProperty("testng.output.dir")
File orignialReportFile = new File(reportDir, oldString);
logger.info("reportFile is::" + System.getProperty("user.dir") + "/" + System.getProperty("testng.outpur.dir")
+ "/" + System.getProperty("emailable.report2.name"));

File newReportFile = new File(
System.getProperty("user.dir") + "/" + System.getProperty("testng.outpur.dir") + "/" + newString);
logger.info("New reportFile is::" + System.getProperty("user.dir") + "/"
+ System.getProperty("testng.outpur.dir") + "/" + newString);

if (orignialReportFile.exists()) {
if (orignialReportFile.renameTo(newReportFile)) {
orignialReportFile.delete();
logger.info("Report File re-named successfully!");

if (ConfigManager.getPushReportsToS3().equalsIgnoreCase("yes")) {
S3Adapter s3Adapter = new S3Adapter();
boolean isStoreSuccess = false;
boolean isStoreSuccess2 = true; // or remove this flag until a second upload is added
try {
isStoreSuccess = s3Adapter.putObject(ConfigManager.getS3Account(), "Adminui", null, null,
newString, newReportFile);
logger.info("isStoreSuccess:: " + isStoreSuccess);

/* Need to figure how to handle EXTENT report handling */

} catch (Exception e) {
logger.error("error occured while pushing the object" + e.getMessage());
}
if (isStoreSuccess && isStoreSuccess2) {
logger.info("Pushed report to S3");
} else {
logger.error("Failed while pushing file to S3");
}
}
} else {
logger.error("Failed to rename report to: " + newName);
logger.error("Renamed report file doesn't exist");
}
} else {
logger.error("Original report File does not exist!");
}
}

Expand Down