All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.shaft.tools.io.internal.ReportHelper Maven / Gradle / Ivy

Go to download

SHAFT is a unified test automation engine. Powered by best-in-class frameworks, SHAFT provides a wizard-like syntax to drive your automation efficiently, maximize your ROI, and minimize your learning curve. Stop reinventing the wheel. Upgrade now!

There is a newer version: 8.2.20240402
Show newest version
package com.shaft.tools.io.internal;

import com.shaft.cli.FileActions;
import com.shaft.driver.SHAFT;
import com.shaft.tools.io.ReportManager;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class ReportHelper {
    public static void attachEngineLog() {
        String executionEndTimestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
        ReportManagerHelper.attachEngineLog(executionEndTimestamp);
    }

    public static void attachIssuesLog() {
        String executionEndTimestamp = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
        ReportManagerHelper.attachIssuesLog(executionEndTimestamp);
    }

    public static void attachImportantLinks() {
        ReportManager.logDiscrete("Initializing Important Links...");
        disableLogging();
        String importantLinks = """
                """;

        ReportManagerHelper.attach("HTML", "Important Links", importantLinks);
        enableLogging();
    }

    public static void enableLogging() {
        SHAFT.Properties.reporting.set().disableLogging(false);
    }

    public static void disableLogging() {
        SHAFT.Properties.reporting.set().disableLogging(true);
    }

    public static void attachPropertyFiles() {
        ReportManager.logDiscrete("Initializing Properties...");
        disableLogging();
        if (FileActions.getInstance().doesFileExist(SHAFT.Properties.paths.properties())) {
            List> attachments = new ArrayList<>();

            var propertyFiles = Arrays.asList(FileActions.getInstance().listFilesInDirectory(SHAFT.Properties.paths.properties(), null).replaceAll("default" + System.lineSeparator(), "").replaceAll(".*json", "").trim().split(System.lineSeparator()));
            propertyFiles.forEach(file -> attachments.add(Arrays.asList("Properties", file.replace(".properties", ""), FileActions.getInstance().readFile(SHAFT.Properties.paths.properties() + File.separator + file))));

            var jsonFiles = Arrays.asList(FileActions.getInstance().listFilesInDirectory(SHAFT.Properties.paths.properties(), null).replaceAll("default" + System.lineSeparator(), "").replaceAll(".*properties", "").trim().split(System.lineSeparator()));
            jsonFiles.forEach(file -> attachments.add(Arrays.asList("JSON", file.replace(".json", ""), FileActions.getInstance().readFile(SHAFT.Properties.paths.properties() + File.separator + file))));

            ReportManagerHelper.logNestedSteps("Property Files", attachments);
        }
        enableLogging();
    }

    public static void attachCucumberReport() {
        if (FileActions.getInstance().doesFileExist("allure-results/cucumberReport.html")) {
            ReportManagerHelper.attach("HTML", "Cucumber Execution Report", FileActions.getInstance().readFile("allure-results/cucumberReport.html"));
        }
    }

    public static void attachExtentReport() {
        ReportManagerHelper.extentReportsFlush();
        if (SHAFT.Properties.reporting.attachExtentReportsToAllureReport()) {
            if (SHAFT.Properties.reporting.generateExtentReports() && FileActions.getInstance().doesFileExist(ReportManagerHelper.getExtentReportFileName())) {
                ReportManagerHelper.attach("HTML", "Extent Emailable Execution Report", FileActions.getInstance().readFile(ReportManagerHelper.getExtentReportFileName()));
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy