extent-framework / extentreports-java

Extent Reporting Library, Java
http://extentreports.com
Apache License 2.0
221 stars 126 forks source link

Extent Report is not getting generated in bamboo #87

Closed omprakashch closed 5 years ago

omprakashch commented 5 years ago

Hi,

We are trying to generate extent report using version2 but we are seeing the below error.

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process

Caused by: java.lang.ExceptionInInitializerError Caused by: java.lang.NullPointerException at java.io.File.(File.java:277) com.relevantcodes.extentreports.Report.setFilePath(Report.java:527)

This is an intermittent issue and because of this our job is not running at all.But sometimes we are able to generate the report and there is no difference in code in both the cases.

Below is the code what we are suing for report generation:

import java.io.File;

import org.openqa.selenium.Platform;

import com.relevantcodes.extentreports.ExtentReports;

public class ExtentManager extends TestBase{ private static ExtentReports extent; private static Platform platform; private static String reportFileName = "Test-Automaton-Report.html"; private static String macPath = System.getProperty("user.dir")+ "/TestReport"; private static String windowsPath = System.getProperty("user.dir")+ "/TestReport"; //private static String windowsPath = "./TestReport";

private static String macReportFileLoc = macPath + "/" + reportFileName;
private static String winReportFileLoc = windowsPath + "/" + reportFileName;

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.config().setTestViewChartLocation(ChartLocation.BOTTOM);
    htmlReporter.config().setChartVisibilityOnOpen(true);
    htmlReporter.config().setTheme(Theme.STANDARD);
    htmlReporter.config().setDocumentTitle(fileName);
    htmlReporter.config().setEncoding("utf-8");
    htmlReporter.config().setReportName(fileName);*/

    extent = new ExtentReports(fileName);
    //extent.attachReporter(fileName);
    //extent.addSystemInfo("Environment",prop.getProperty("env"));
    return extent;
}

//Select the extent report file location based on platform
private static String getReportFileLocation (Platform platform) {
    String reportFileLocation = null;
    switch (platform) {
        case MAC:
            reportFileLocation = macReportFileLoc;
            createReportPath(macPath);
            System.out.println("ExtentReport Path for MAC: " + macPath + "\n");
            break;
        case WINDOWS:
            reportFileLocation = winReportFileLoc;
            createReportPath(windowsPath);
            System.out.println("ExtentReport Path for WINDOWS: " + windowsPath + "\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()) {
        if (testDirectory.mkdir()) {
            System.out.println("Directory: " + path + " is created!" );
        } else {
            System.out.println("Failed to create directory: " + path);
        }
    } else {
        System.out.println("Directory already exists: " + path);
    }
}

//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;
}

}

import java.io.File; import java.io.IOException;

import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult;

/import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest;/ import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus;

public class TestListener extends TestBase implements ITestListener {

//Extent Report Declarations
private static ExtentReports extent = ExtentManager.createInstance();
private ThreadLocal<ExtentTest> test = new ThreadLocal<ExtentTest>();

public synchronized void onStart(ITestContext context) {
    System.out.println("Extent Reports Version 3 Test Suite started!");
}

public synchronized void onFinish(ITestContext context) {
    System.out.println(("Extent Reports Version 3  Test Suite is ending!"));
    extent.flush();
}

public synchronized void onTestStart(ITestResult result) {
    System.out.println((result.getMethod().getMethodName() + " started!"));
    //ExtentTest extentTest = extent.createTest(result.getMethod().getMethodName(),result.getMethod().getDescription());
    ExtentTest extentTest = extent.startTest(result.getMethod().getMethodName(),result.getTestClass().getName());
    test.set(extentTest);
}

public synchronized void onTestSuccess(ITestResult result) {
    System.out.println((result.getMethod().getMethodName() + " passed!"));
    test.get().log(LogStatus.PASS,"Test passed");
}

public synchronized void onTestFailure(ITestResult result) {
    System.out.println((result.getMethod().getMethodName() + " failed!"));
    test.get().log(LogStatus.FAIL,result.getThrowable());
    //test.get().fail(result.getThrowable());
    TakesScreenshot ts = (TakesScreenshot)getDriver();
    File srcFile = ts.getScreenshotAs(OutputType.FILE);
    try {
    FileUtils.copyFile(srcFile, new File("./TestReport/"+result.getName()+".PNG"));
    } catch (IOException e) {
     e.printStackTrace();
    }
    try {
        String currentdir = System.getProperty("user.dir");
        test.get().addScreenCapture(currentdir+"/TestReport/"+result.getName()+".PNG");
    } catch (Exception e){
        e.printStackTrace();
    }
}

public synchronized void onTestSkipped(ITestResult result) {
    System.out.println((result.getMethod().getMethodName() + " skipped!"));
    test.get().log(LogStatus.SKIP,result.getThrowable());
    //test.get().skip(result.getThrowable());
}

public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
    System.out.println(("onTestFailedButWithinSuccessPercentage for " + result.getMethod().getMethodName()));
}

}

And below are the dependancies

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.13.0</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
    </dependency>

    <dependency>
        <groupId>org.apache.directory.studio</groupId>
        <artifactId>org.apache.commons.io</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.9</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.9</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-scratchpad</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>ooxml-schemas</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>openxml4j</artifactId>
        <version>1.0-beta</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
    <!-- <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> 
        <version>3.0.0</version> </dependency> -->
    <!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>2.41.2</version>
    </dependency>
    <!-- <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.1.5</version>
    </dependency> -->
    <!-- https://mvnrepository.com/artifact/com.redhat.qe/testng-listeners -->
    <dependency>
        <groupId>com.redhat.qe</groupId>
        <artifactId>testng-listeners</artifactId>
        <version>1.0.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc -->
    <!-- <dependency> <groupId>db2jcc</groupId> <artifactId>db2jcc</artifactId> 
        <scope>system</scope> <version>1.0</version> <systemPath>${basedir}/src/lib/db2jcc.jar</systemPath> 
        </dependency> -->
    <!-- https://mvnrepository.com/artifact/com.ibm/db2jcc -->
    <dependency>
        <groupId>com.ibm.db2.jcc</groupId>
        <artifactId>db2jcc</artifactId>
        <version>db2jcc4</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>2.0.0-alpha0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
org.apache.commons commons-dbcp2 2.1
</dependencies>

Please help me on this

virenv commented 5 years ago

@omprakashch : Would it be possible for you to upgrade to the latest version of ExtentReports. We have version 4 out. http://extentreports.com/documentation/

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

stale[bot] commented 5 years ago

This issue has been automatically closed because of inactivity.