> listOfNewIssuesForFailedTests = new ArrayList<>();
private static String featureName = "";
+ private static String extentReportsFolderPath = "";
+ private static ExtentReports extentReport;
+ private static ExtentTest extentTest;
+ private static String extentReportFileName;
+ private static String generateExtentReports;
+
private ReportManager() {
throw new IllegalStateException("Utility class");
}
+ public static String getExtentReportFileName() {
+ return extentReportFileName;
+ }
+
public static void setOpenIssuesForFailedTestsCounter(int openIssuesForFailedTestsCounter) {
ReportManager.openIssuesForFailedTestsCounter = openIssuesForFailedTestsCounter;
}
@@ -344,7 +363,7 @@ public static void attachIssuesLog(String executionEndTimestamp) {
}
}
- public static void openAllureReportAfterExecution() {
+ protected static void openAllureReportAfterExecution() {
String commandToOpenAllureReport;
if (Boolean.TRUE.equals(Boolean.valueOf(System.getProperty("openAllureReportAfterExecution").trim()))
&& System.getProperty("executionAddress").trim().equals("local")) {
@@ -358,7 +377,7 @@ public static void openAllureReportAfterExecution() {
}
}
- public static void generateAllureReportArchive() {
+ protected static void generateAllureReportArchive() {
if (Boolean.TRUE.equals(Boolean.valueOf(System.getProperty("generateAllureReportArchive").trim()))
&& System.getProperty("executionAddress").trim().equals("local")) {
logDiscrete("Generating Allure Report Archive...");
@@ -418,6 +437,89 @@ public static void setFeatureName(String featureName) {
ReportManager.featureName = featureName;
}
+ private static boolean generateExtentReports() {
+ if (generateExtentReports == null) {
+ generateExtentReports = System.getProperty("generateExtentReports").trim();
+ }
+ return Boolean.parseBoolean(generateExtentReports);
+ }
+
+ public static void initializeExtentReports() {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentReportsFolderPath = System.getProperty("extentReportsFolderPath").trim();
+ cleanExtentReportsDirectory();
+ extentReportFileName = extentReportsFolderPath + "ExtentReports_" + (new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss-SSSS-aaa")).format(System.currentTimeMillis()) + ".html";
+ extentReport = new ExtentReports();
+ ExtentSparkReporter spark = new ExtentSparkReporter(extentReportFileName)
+ .viewConfigurer()
+ .viewOrder()
+ .as(new ViewName[]{ViewName.DASHBOARD, ViewName.TEST, ViewName.EXCEPTION})
+ .apply();
+ extentReport.attachReporter(spark);
+ spark.config().setTheme(Theme.STANDARD);
+ spark.config().setDocumentTitle("Extent Reports");
+ spark.config().setReportName("Extent Reports - Powered by SHAFT_Engine");
+ }
+ }
+
+ private static void cleanExtentReportsDirectory() {
+ if (Boolean.TRUE.equals(
+ Boolean.valueOf(System.getProperty("cleanExtentReportsDirectoryBeforeExecution")))) {
+ FileActions.deleteFolder(extentReportsFolderPath.substring(0, extentReportsFolderPath.length() - 1));
+ }
+
+ }
+
+ public static void extentReportsReset() {
+ extentTest = null;
+ }
+
+ public static void extentReportsCreateTest(String testName, String testDescription) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ if (testDescription.equals("")) {
+ extentTest = extentReport.createTest(testName);
+ } else {
+ extentTest = extentReport.createTest(testDescription);
+ }
+ }
+ }
+
+ public static void extentReportsPass(String message) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentTest.pass(message);
+ }
+ }
+
+ public static void extentReportsFail(String message) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentTest.fail(message);
+ }
+ }
+
+ public static void extentReportsFail(Throwable t) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentTest.fail(t);
+ }
+ }
+
+ public static void extentReportsSkip(String message) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentTest.skip(message);
+ }
+ }
+
+ public static void extentReportsSkip(Throwable t) {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentTest.skip(t);
+ }
+ }
+
+ public static void extentReportsFlush() {
+ if (Boolean.TRUE.equals(generateExtentReports())) {
+ extentReport.flush();
+ }
+ }
+
protected static void logClosureActivitiesInitialization() {
String closureActivities = "Test Closure Activities";
createImportantReportEntry(closureActivities, true);
@@ -465,6 +567,10 @@ private static void createReportEntry(String logText, Boolean addToFullLog) {
}
String log = REPORT_MANAGER_PREFIX + logText.trim() + " @" + timestamp;
Reporter.log(log, true);
+ if (extentTest != null && !logText.contains("created attachment") && !logText.contains(" -1) {
- baos.write(buffer, 0, len);
- }
- baos.flush();
+ attachmentContent.transferTo(baos);
} catch (IOException e) {
String error = "Error while creating Attachment";
slf4jLogger.info(error, e);
Reporter.log(error, false);
}
- attachmentContent = new ByteArrayInputStream(baos.toByteArray());
- attachmentContentCopy = new ByteArrayInputStream(baos.toByteArray());
-
String attachmentDescription = "Attachment: " + attachmentType + " - " + attachmentName;
+ attachBasedOnFileType(attachmentType, attachmentName, baos, attachmentDescription);
+ logAttachmentAction(attachmentType, attachmentName, baos);
+ }
- attachBasedOnFileType(attachmentType, attachmentName, attachmentContent, attachmentDescription);
+ private static synchronized void attachBasedOnFileType(String attachmentType, String attachmentName,
+ ByteArrayOutputStream attachmentContent, String attachmentDescription) {
+ if (attachmentType.toLowerCase().contains("screenshot")) {
+ Allure.addAttachment(attachmentDescription, "image/png", new ByteArrayInputStream(attachmentContent.toByteArray()), ".png");
+ attachImageToExtentReport("image/png", new ByteArrayInputStream(attachmentContent.toByteArray()));
+ } else if (attachmentType.toLowerCase().contains("recording")) {
+ Allure.addAttachment(attachmentDescription, "video/mp4", new ByteArrayInputStream(attachmentContent.toByteArray()), ".mp4");
+ // attachmentDescription, "video/quicktime", attachmentContent, ".mov");
+ // attachmentDescription, "video/webm", attachmentContent, ".webm");
+ // attachmentDescription, "video/mp4", attachmentContent, ".mp4");
+ // attachmentDescription, "video/ogg", attachmentContent, ".ogg");
+ } else if (attachmentType.toLowerCase().contains("gif")) {
+ Allure.addAttachment(attachmentDescription, "image/gif", new ByteArrayInputStream(attachmentContent.toByteArray()), ".gif");
+ attachImageToExtentReport("image/gif", new ByteArrayInputStream(attachmentContent.toByteArray()));
+ } else if (attachmentType.toLowerCase().contains("csv") || attachmentName.toLowerCase().contains("csv")) {
+ Allure.addAttachment(attachmentDescription, "text/csv", new ByteArrayInputStream(attachmentContent.toByteArray()), ".csv");
+ attachCodeBlockToExtentReport("text/csv", new ByteArrayInputStream(attachmentContent.toByteArray()));
+ } else if (attachmentType.toLowerCase().contains("xml") || attachmentName.toLowerCase().contains("xml")) {
+ Allure.addAttachment(attachmentDescription, "text/xml", new ByteArrayInputStream(attachmentContent.toByteArray()), ".xml");
+ attachCodeBlockToExtentReport("text/xml", new ByteArrayInputStream(attachmentContent.toByteArray()));
+ } else if (attachmentType.toLowerCase().contains("excel") || attachmentName.toLowerCase().contains("excel")) {
+ Allure.addAttachment(attachmentDescription, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", new ByteArrayInputStream(attachmentContent.toByteArray()), ".xlsx");
+ } else if (attachmentType.toLowerCase().contains("json") || attachmentName.toLowerCase().contains("json")) {
+ Allure.addAttachment(attachmentDescription, "text/json", new ByteArrayInputStream(attachmentContent.toByteArray()), ".json");
+ attachCodeBlockToExtentReport("text/json", new ByteArrayInputStream(attachmentContent.toByteArray()));
+ } else if (attachmentType.toLowerCase().contains("engine logs")) {
+ Allure.addAttachment(attachmentDescription, "text/plain", new ByteArrayInputStream(attachmentContent.toByteArray()), ".txt");
+ } else {
+ Allure.addAttachment(attachmentDescription, new ByteArrayInputStream(attachmentContent.toByteArray()));
+ }
+ }
+ private static synchronized void logAttachmentAction(String attachmentType, String attachmentName, ByteArrayOutputStream attachmentContent) {
if (!(attachmentType.equals(SHAFT_ENGINE_LOGS_ATTACHMENT_TYPE) && attachmentName.equals("Execution log"))) {
createReportEntry("Successfully created attachment [" + attachmentType + " - " + attachmentName + "]",
false);
@@ -557,7 +688,7 @@ private static void createAttachment(String attachmentType, String attachmentNam
String theString;
BufferedReader br = new BufferedReader(
- new InputStreamReader(attachmentContentCopy, StandardCharsets.UTF_8));
+ new InputStreamReader(new ByteArrayInputStream(attachmentContent.toByteArray()), StandardCharsets.UTF_8));
theString = br.lines().collect(Collectors.joining(System.lineSeparator()));
if (!theString.isEmpty()) {
String logEntry = REPORT_MANAGER_PREFIX + "Debugging Attachment Entry" + " @" + timestamp
@@ -567,30 +698,33 @@ private static void createAttachment(String attachmentType, String attachmentNam
}
}
- private static synchronized void attachBasedOnFileType(String attachmentType, String attachmentName,
- InputStream attachmentContent, String attachmentDescription) {
- if (attachmentType.toLowerCase().contains("screenshot")) {
- Allure.addAttachment(attachmentDescription, "image/png", attachmentContent, ".png");
- } else if (attachmentType.toLowerCase().contains("recording")) {
- Allure.addAttachment(attachmentDescription, "video/mp4", attachmentContent, ".mp4");
- // attachmentDescription, "video/quicktime", attachmentContent, ".mov");
- // attachmentDescription, "video/webm", attachmentContent, ".webm");
- // attachmentDescription, "video/mp4", attachmentContent, ".mp4");
- // attachmentDescription, "video/ogg", attachmentContent, ".ogg");
- } else if (attachmentType.toLowerCase().contains("gif")) {
- Allure.addAttachment(attachmentDescription, "image/gif", attachmentContent, ".gif");
- } else if (attachmentType.toLowerCase().contains("csv") || attachmentName.toLowerCase().contains("csv")) {
- Allure.addAttachment(attachmentDescription, "text/csv", attachmentContent, ".csv");
- } else if (attachmentType.toLowerCase().contains("xml") || attachmentName.toLowerCase().contains("xml")) {
- Allure.addAttachment(attachmentDescription, "text/xml", attachmentContent, ".xml");
- } else if (attachmentType.toLowerCase().contains("excel") || attachmentName.toLowerCase().contains("excel")) {
- Allure.addAttachment(attachmentDescription, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", attachmentContent, ".xlsx");
- } else if (attachmentType.toLowerCase().contains("json") || attachmentName.toLowerCase().contains("json")) {
- Allure.addAttachment(attachmentDescription, "text/json", attachmentContent, ".json");
- } else if (attachmentType.toLowerCase().contains("engine logs")) {
- Allure.addAttachment(attachmentDescription, "text/plain", attachmentContent, ".txt");
- } else {
- Allure.addAttachment(attachmentDescription, attachmentContent);
+ private static void attachCodeBlockToExtentReport(String attachmentType, InputStream attachmentContent) {
+ if (extentTest != null) {
+ try {
+ String codeBlock = IOUtils.toString(attachmentContent, StandardCharsets.UTF_8.name());
+ switch (attachmentType) {
+ case "text/json" -> extentTest.info(MarkupHelper.createCodeBlock(codeBlock, CodeLanguage.JSON));
+ case "text/xml" -> extentTest.info(MarkupHelper.createCodeBlock(codeBlock, CodeLanguage.XML));
+ default -> extentTest.info(MarkupHelper.createCodeBlock(codeBlock));
+ }
+ } catch (IOException e) {
+ ReportManager.logDiscrete("Failed to attach code block to extentReport.");
+ }
+ }
+ }
+
+ private static void attachImageToExtentReport(String attachmentType, InputStream attachmentContent) {
+ if (extentTest != null) {
+ try {
+ String image = Base64.getEncoder().encodeToString(IOUtils.toByteArray(attachmentContent));
+ if (attachmentType.toLowerCase().contains("gif")) {
+ extentTest.addScreenCaptureFromBase64String(image);
+ } else {
+ extentTest.info(MediaEntityBuilder.createScreenCaptureFromBase64String(image).build());
+ }
+ } catch (IOException e) {
+ ReportManager.logDiscrete("Failed to attach screenshot to extentReport.");
+ }
}
}
@@ -621,7 +755,6 @@ private static void writeEnvironmentVariablesToAllureResultsDirectory() {
if (propertyValue.contains("&")) {
propertyValue = propertyValue.replace("&", "&");
}
-
String parameter = "" + "" + propertyKey + "" + "" + propertyValue
+ "" + "";
if (propertyKey.equals(SHAFT_ENGINE_VERSION_PROPERTY_NAME)) {
@@ -670,7 +803,7 @@ private static void writeGenerateReportShellFilesToProjectDirectory() {
if (SystemUtils.IS_OS_WINDOWS) {
// create windows batch file
commandsToServeAllureReport = Arrays.asList("@echo off",
- "set path=" + allureExtractionLocation + "allure-" + allureVersion + "\\bin;%path%",
+ "set path=" + allureExtractionLocation + "allure-" + allureVersion + "\\bin;" + System.getProperty("java.home") + "\\bin;%path%",
"allure serve " + allureResultsFolderPath.substring(0, allureResultsFolderPath.length() - 1),
"pause", "exit");
FileActions.writeToFile("", "generate_allure_report.bat", commandsToServeAllureReport);
@@ -720,7 +853,7 @@ private static void writeOpenReportShellFilesToGeneratedDirectory() {
// create windows batch file
commandsToOpenAllureReport = Arrays.asList("@echo off",
- "set path=allure\\allure-" + System.getProperty(ALLURE_VERSION_PROPERTY_NAME) + "\\bin;%path%",
+ "set path=allure\\allure-" + System.getProperty(ALLURE_VERSION_PROPERTY_NAME) + "\\bin;" + System.getProperty("java.home") + ";%path%",
"allure open allure-report", "pause", "exit");
FileActions.writeToFile("generatedReport/", "open_allure_report.bat", commandsToOpenAllureReport);
diff --git a/src/main/java/com/shaft/tools/listeners/InvokedMethodListener.java b/src/main/java/com/shaft/tools/listeners/InvokedMethodListener.java
index 0a880a1c81d..c81591398fc 100755
--- a/src/main/java/com/shaft/tools/listeners/InvokedMethodListener.java
+++ b/src/main/java/com/shaft/tools/listeners/InvokedMethodListener.java
@@ -38,21 +38,31 @@ public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
ReportManager.log(e);
}
ITestNGMethod testMethod = method.getTestMethod();
+
+ String className;
+ String methodName;
+ String methodDescription = "";
+
if (!testMethod.getQualifiedName().contains("AbstractTestNGCucumberTests")) {
if (testMethod.isTest()) {
+ className = ReportManager.getTestClassName();
+ methodName = ReportManager.getTestMethodName();
if (testMethod.getDescription() != null) {
- ReportManager.logTestInformation(ReportManager.getTestClassName(), ReportManager.getTestMethodName(),
- testMethod.getDescription());
- } else {
- ReportManager.logTestInformation(ReportManager.getTestClassName(), ReportManager.getTestMethodName(), "");
+ methodDescription = testMethod.getDescription();
}
+
+ ReportManager.logTestInformation(className, methodName, methodDescription);
+ ReportManager.extentReportsCreateTest(className + "." + methodName, methodDescription);
} else if (testMethod instanceof ConfigurationMethod) {
// org.testng.internal.ConfigurationMethod
// ReportManager.logDiscrete("Current TestNG Method Name: " +
// testMethod.getClass().getName());
// configuration method information is not added to any logger (TestNG.Reporter)
- ReportManager.logConfigurationMethodInformation(testMethod.getTestClass().getName(),
- testMethod.getMethodName());
+ className = testMethod.getTestClass().getName();
+ methodName = testMethod.getMethodName();
+
+ ReportManager.logConfigurationMethodInformation(className, methodName);
+ ReportManager.extentReportsReset();
}
}
// implementing the new kill switch at the start of every test method
@@ -119,9 +129,22 @@ private void updateIssuesLog(ITestResult testResult, ITestNGMethod testMethod) {
if (testResult != null && testResult.getStatus() == ITestResult.SUCCESS) {
// if test passed
reportOpenIssueStatus(testMethod, true);
+ ReportManager.extentReportsPass("Test Passed.");
} else if (testResult != null && testResult.getStatus() == ITestResult.FAILURE) {
// if test failed
reportOpenIssueStatus(testMethod, false);
+ if (testResult.getThrowable() != null) {
+ ReportManager.extentReportsFail(testResult.getThrowable());
+ } else {
+ ReportManager.extentReportsFail("Test Failed.");
+ }
+ } else if (testResult != null && testResult.getStatus() == ITestResult.SKIP) {
+ // if test skipped
+ if (testResult.getThrowable() != null) {
+ ReportManager.extentReportsSkip(testResult.getThrowable());
+ } else {
+ ReportManager.extentReportsSkip("Test Skipped as it depends on unsuccessfully executed methods.");
+ }
}
}
diff --git a/src/main/java/com/shaft/tools/listeners/SuiteListener.java b/src/main/java/com/shaft/tools/listeners/SuiteListener.java
index b8d42e4c4ec..cc364b859bd 100755
--- a/src/main/java/com/shaft/tools/listeners/SuiteListener.java
+++ b/src/main/java/com/shaft/tools/listeners/SuiteListener.java
@@ -20,6 +20,7 @@ public void onStart(ISuite suite) {
PropertyFileManager.readPropertyFiles(ScreenshotManager.getAiAidedElementIdentificationFolderpath());
}
ProjectStructureFactory.initialize();
+ ReportManager.initializeExtentReports();
ReportManager.prepareAllureReportingEnvironment();
ReportManager.logEngineVersion();
if (!(suite.getAllMethods().size() == 1 && suite.getAllMethods().get(0).getMethodName().equals("runScenario"))) {
@@ -29,11 +30,4 @@ public void onStart(ISuite suite) {
ReportManager.setDiscreteLogging(Boolean.parseBoolean(System.getProperty("alwaysLogDiscreetly")));
ReportManager.setDebugMode(Boolean.valueOf(System.getProperty("debugMode")));
}
-
- @Override
- public void onFinish(ISuite suite) {
- ReportManager.setDiscreteLogging(true);
- ReportManager.generateAllureReportArchive();
- ReportManager.openAllureReportAfterExecution();
- }
}
\ No newline at end of file
diff --git a/src/main/javadoc/index.html b/src/main/javadoc/index.html
index 67343be19f6..5962791d8f7 100644
--- a/src/main/javadoc/index.html
+++ b/src/main/javadoc/index.html
@@ -378,15 +378,22 @@ Configuration Manager
+
+
+
• ExperimentalFeature* Enabling maximumPerformanceMode will disable all complementary features to ensure the fastest execution possible with a 400% calculated performance boost.
@@ -1177,6 +1184,60 @@ Configuration Manager
+
+
+
+
+
+