Файл отчета экстента не экспортируется при выполнении в виде пакета maven - PullRequest
0 голосов
/ 12 января 2020
  • Когда я выполняю свои тесты с пакетом mvn (файл jar), всегда не удается создать каталог отчетов в папке / target ... при выполнении из среды IDE это работает штрафа ..

  • Но после вызова показанного ниже метода takecreenshot () каталог создается для failScreenshots

  • Когда я выполняю maven снова, без очистки (mvn clean), поскольку каталог уже существует, теперь файл отчета экспортируется безупречно.

, почему всегда не удается создать каталог отчета в / целевая папка .. когда я выполняю в первый раз?

В чем проблема, я не могу ее отладить!

ExtentReportGenerator. java

publi c класс ExtentReportGenerator расширяет BaseTest {

static Calendar instance = Calendar.getInstance();
static Date time = instance.getTime();

private static ExtentReports extent;
private static InputStream fileInput;
private static Platform platform;
private static String reportFileName = "ExtentReports-Version3-Test-Automation-Report"+time+".html";
private static String linuxPath = System.getProperty("user.dir")+ "/src/main/resources/Reports";
private static String windowsPath = System.getProperty("user.dir")+ "\\Reports";
private static String macPath = System.getProperty("user.dir")+ "/src/main/resources/Reports";
private static String remotePath = "/";
private static String macReportFileLoc = macPath + "/" + reportFileName;
private static String linuxReportFileLoc = linuxPath + "/" + reportFileName;
private static String winReportFileLoc = windowsPath + "\\" + reportFileName;
//    private static String remoteFileLoc = remotePath + reportFileName;
private static String remote;

public static ExtentReports getInstance()  {
    if (extent == null)
        createInstance();
    return extent;
}
//Create an extent report instance
public static ExtentReports createInstance(){
    platform = getCurrentPlatform();
    String fileName = getReportFileLocation(platform);
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
    htmlReporter.setAppendExisting(false);
    htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
    htmlReporter.config().setChartVisibilityOnOpen(true);
    htmlReporter.config().setTheme(Theme.STANDARD);
    htmlReporter.config().setDocumentTitle("My StartUp Equity Automation Result");
    htmlReporter.config().setEncoding("utf-8");
    htmlReporter.config().setReportName("My StartUp Equity Automation Result");

    extent = new ExtentReports();

    extent.setSystemInfo("OS",System.getProperty("os.name"));
    extent.setSystemInfo("Host Name",System.getProperty("user.name"));
    extent.setSystemInfo("Java Version",System.getProperty("java.version"));

    extent.attachReporter(htmlReporter);
    // extent.set

    return extent;
}

//Select the extent report file location based on platform
private static String getReportFileLocation (Platform platform) {
    String reportFileLocation = null;
    switch (platform) {
        case LINUX:
            reportFileLocation = linuxReportFileLoc;
            createReportPath(linuxPath);
            System.out.println("ExtentReport Path for Linux: " + linuxPath + "\n");

            break;
        case WINDOWS:
            reportFileLocation = winReportFileLoc;
            createReportPath(windowsPath);
            System.out.println("ExtentReport Path for WINDOWS: " + windowsPath + "\n");
            break;
        case MAC:
            reportFileLocation = macReportFileLoc;
            createReportPath(macPath);
            System.out.println("ExtentReport Path for Remote: " + macPath + "\n");
            break;
        default:
            System.out.println("ExtentReport path has not been set! There is a problem!\n");
            break;
    }
    return reportFileLocation;
}

//Create the report path if it does not exist
private static void createReportPath (String path) {

    File testDirectory = new File(path);
    if (!testDirectory.exists()) {
        try{
            if (testDirectory.mkdir()) {
                System.out.println("Directory: " + path + " is created!" );
            } else {
                System.out.println("Failed to create directory: " + path);
            }
        } catch (Exception e){
            e.printStackTrace();
            System.out.println("Some Problem when creating directory");
        }
    }
}

//Get current platform
private static Platform getCurrentPlatform () {
    if (platform == null) {
        String operSys = System.getProperty("os.name").toLowerCase();
        if (operSys.contains("win")) {
            platform = Platform.WINDOWS;
        } else if (operSys.contains("nix") || operSys.contains("nux")
                || operSys.contains("aix")) {
            platform = Platform.LINUX;
        } else if (operSys.contains("mac")) {
            platform = Platform.MAC;
        }
    }
    return platform;
}

}

public static String takeScreenshot() throws IOException {

    Date date = new Date();

    long currentTime = date.getTime();
    File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

    String path = System.getProperty("user.dir") + "/src/main/resources/FailureScreenshots/Scshot" + currentTime
            + ".png";
    System.out.println("captured Screenshot and exporting to path " + path);
    FileUtils.copyFile(screenshot, new File(path));
    return path;
}

Команда Maven: и ошибка на консоли letsventure@LetsVentures-MacBook-Pro target% java -cp "MSE- docker .jar: MSE- docker -tests.jar: libs / *" -Dremote = true org.testng.TestNG ../src/main/resources/TestRunner/testng.xml Не удалось создать каталог: / Users / letsventure / MSE-Automation / mse-Automation / Local-MSE / target / src / main / resources / Отчеты Путь к экстенту отчета для удаленного: / Users / letsventure / MSE-Automation / mse-Automation / Local -MSE / цель / SRC / основные / ресурсы / Отчеты

...