extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

I m facing null pointer exception in the below mentioned scenario

Open sanmativardhaman opened this issue 8 years ago • 4 comments

i have created a Base test class, which has all declarations w.r.t Extent reports,

i,e public class BaseTest { public WebDriver driver; public ExtentReports reports; public ExtentTest logger; public WebDriverWait wait; public WebElement myElement; public static Calendar c = Calendar.getInstance();

@BeforeSuite
public void baseSetUp()
{
	reports=new    

ExtentReports(System.getProperty("user.dir")+"\Reports\"+dateStamp()+"\"+"API_SmokeTest.html"); }

@AfterSuite
public void tearDown()
{
	reports.endTest(logger);
	reports.flush();
}

}. i have two test classes which extends this base test. In test class one and two i have created logger object i,e logger =reports.StartTest("tc_01") Test class one runs fine, In test class two also i have same line, i,e logger =reports.startTest("tc_02"), when i run my testng.xml, only first testng class is executing while the second class throws 'null pointer exception" for this line logger =reports.startTest("tc_02"). Kindly help

sanmativardhaman avatar Dec 20 '17 07:12 sanmativardhaman

As you are creating reports.StartTest for each test meaning each method will be treated as a test. In this case, Try creating logger =reports.StartTest("tc_01") in a @beforeMethod and @aftermethod in baseclass

@BeforeMethod()
public void setupExtentTest(Method result) 
{
// result.getName() = name of the test method executing
 logger =reports.StartTest(result.getName())
}

@afterMethod()
public void teardown(ITestResult result)
{
//result.getname() = name of the test method executing
reports.endTest(result.getname());
reports.flush();
}

@aftermethod will declare your testcase finished and it will close that extenttest instance. in @aftersuite you will close the report and flush the report.

I hope this will help.

dipesh17 avatar Feb 20 '18 13:02 dipesh17

Even I am also facing the same problem. ExtentReports report; ExtentTest logger;

  1. I initialized in @BeforeSuite
  2. Then Initialized in @BeforeMethod
  3. In testng.xml there are 2 classes Class1 & Class2
  4. On execution of testng.xml - All @Test of class1 runs completely but Class2 throws null pointer exception error when it reads in BeforeMethod(Initialized as mentioned in step2)

Note: When I change BeforeSuite to BeforeMethod i.e initialization of is done in BeforeClass then It runs fine but it produces extent report of only 1 class.

Also I am using Aftermethod to Flush the report and quit driver. Any solution?

VikashGittt avatar Sep 09 '18 08:09 VikashGittt

I am also facing the same issue.. Found any solution for this?

VinWip avatar Sep 13 '18 09:09 VinWip

@anshooarora Please help to resolve this.

VinWip avatar Sep 13 '18 10:09 VinWip