anshooarora / extentreports-java

Community version of Extent API for Java has moved to https://github.com/extent-framework/
http://extentreports.com
Other
529 stars 318 forks source link

java.lang.NullPointerException when running testNG xml on command line with extent Report 3.0.6 #935

Open katimmy opened 7 years ago

katimmy commented 7 years ago

Getting a null Pointer when i execute the testNG.xml from commandLine if i have extent reports 3.0.6 intergrated

public void beforeSuite() throws Exception {
  /**
     * Initiate the Extent Report
     */
    Log.info("Initializing and creating report Now");
    extent = ExtentManager.createInstance("output/reports/extent.html");
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("output/reports/extent.html");
    extent.setSystemInfo("Environment","Night Run");
    extent.setSystemInfo("Selenium version", "v2.53.0");
    extent.setSystemInfo("Test Environment", "v2.53.0");
    extent.attachReporter(htmlReporter);
    // End of Report Intialisation

}

@BeforeClass public void setup() throws FileNotFoundException {

    Log.info("Running Before Class");

    /**
     * Report class Parent Node Generation
     */
    Log.info("Initializing and Parent Level of the Test in the Report");
    ExtentTest parent = extent.createTest(getClass().getName());
    parent.assignAuthor("Ivan Katumba");
    parentTest.set(parent);

}

@BeforeMethod(alwaysRun = true) public void before(Method method, ITestResult result ,ITestContext iTestContext) throws Exception {

    Test testparams = method.getAnnotation(Test.class);
    /**
     * Addning the Child to the Parent Node on the Extent Report
     */
    Log.info("Initializing the child on the Test in the Report");
    child = ((ExtentTest) parentTest.get()).createNode(testparams.testName());
    child.assignCategory(testparams.groups());
    Log.info("Adding the Author of the report");
    test.set(child);

}

@AfterMethod(alwaysRun = true) public void after(ITestResult result , final ITestContext testContext , Method method) throws IOException {

if (result.getStatus() == ITestResult.FAILURE) {

        ((ExtentTest) test.get()).fail(result.getThrowable());
        TestCaseName = testparams.testName();
        long time = result.getEndMillis() - result.getStartMillis();
        int minutes = (int) ((time / 1000) / 60);
        child.log(Status.INFO, "Execution Time was : "+String.valueOf(minutes));
        String res = captureScreenshot(driver);

        TestCaseName = testparams.testName();
        Log.info("Capturing a screen Shoot for the Failed Test");
        ((ExtentTest) test.get()).addScreenCaptureFromPath(res);
    }
    else if (result.getStatus() == ITestResult.SKIP) {
        ((ExtentTest) test.get()).skip(result.getThrowable());
        TestCaseName = testparams.testName();
        long time = result.getEndMillis() - result.getStartMillis();
        int minutes = (int) ((time / 1000) / 60);
        child.log(Status.INFO, "Execution Time was : "+String.valueOf(minutes));
    }else if(result.getStatus()==ITestResult.SUCCESS) {
        Log.info("Congrats : Your Test Passed");
        TestCaseName = testparams.testName();
        long time = result.getEndMillis() - result.getStartMillis();
        int minutes = (int) ((time / 1000) / 60);
        child.log(Status.INFO, "Execution Time was : "+String.valueOf(minutes));
        ((ExtentTest) test.get()).pass("Test passed");
    }
    Log.info("Saving the Report Now:");
    extent.flush();

}

My Test is

@Test(testName = "Generate Report",groups={"Regressing"},dataProvider = "updateCard") public void genreport(Integer id , String name ) throws Throwable {

    extentLog("Varidating the Data Provider");
    System.out.println("The id is "+ id + " and the name is  : "+ name);
    Assert.assertEquals("7","y");

    }

TestNg file

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

When i excute that i get a NullPointer on the Before Method Child child = ((ExtentTest) parentTest.get()).createNode("TestName"); Line
sainarala421 commented 6 years ago

Even am getting the same exception . Can any one know the solution for above problem how to fix it.