I am getting below null pointer exception when i run LoginTestCase, I have defined ExtentReports in base class and trying to extend it in LoginTestCase
The same code is working fine if i write the extentreport method in LoginTestCase
public class BaseClass
{
public static Properties prop;
public static FileInputStream fis;
public static WebDriver driver;
public static WebDriverWait wait;
public static ExtentHtmlReporter htmlreport;
public static ExtentReports reports;
public static ExtentTest logger;
public BaseClass() throws Throwable
{
prop = new Properties();
try
{
fis = new FileInputStream("C:\\Users\\mna\\eclipse-workspace\\Automation\\src\\com\\config\\ConfigProperties");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
System.out.println("File not found");
}
prop.load(fis);
}
@BeforeTest
public void SetExtentReport()
{
htmlreport = new ExtentHtmlReporter(System.getProperty("user.dir") + "/test-output/myReport.html");
htmlreport.config().setDocumentTitle("Automation Report");
htmlreport.config().setTheme(Theme.STANDARD);
reports = new ExtentReports();
reports.attachReporter(htmlreport);
logger = reports.createTest("test");
}
@AfterTest
public void endExtentReport()
{
reports.flush();
}
@AfterMethod
public void Teardown(ITestResult result)
{
if(result.getStatus() == ITestResult.FAILURE)
{
logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED));
logger.log(Status.FAIL, "TESTCASE IS FAILED - " + result.getName()); //return the name of the method
logger.log(Status.FAIL, "TESTCASE IS FAILED - " + result.getThrowable()); // throw exception to the report
}
else if(result.getStatus() == ITestResult.SKIP)
{
logger.log(Status.SKIP, "TESTCASE IS SKIPPED - " + result.getName());
}
else if(result.getStatus() == ITestResult.SUCCESS)
{
logger.log(Status.PASS, "TESTCASE IS PASSED - " + result.getName());
}
driver.quit();
}
public static void Initalization() throws Throwable
{
if(prop.getProperty("browser").equals("chrome"))
{
String Chropath = "C:\\Users\\mna\\eclipse-workspace\\Automation\\Drivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver",Chropath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--verbose");
chromeOptions.addArguments("--whitelisted-ips=''");
driver = new ChromeDriver(chromeOptions);
wait = new WebDriverWait(driver, 40);
}
else if(prop.getProperty("browser").equals("firefox"))
{
String Firepath = "C:\\Users\\mna\\eclipse-workspace\\Automation\\drivers\\geckodriver.exe";
System.setProperty("webdriver.gecko.driver",Firepath);
driver = new FirefoxDriver();
}
driver.get(prop.getProperty("applicationurl"));
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(testutil.IMPLICIT_WAIT_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(testutil.PAGELOAD_WAIT_TIMEOUT, TimeUnit.SECONDS);
System.out.println("Application launched successfully");
}
}
public class LoginTest extends BaseClass
{
LoginPage loginpage;
DashboardPage dashboardpage;
ExtentHtmlReporter htmlreport;
ExtentReports reports;
ExtentTest logger;
public LoginTest() throws Throwable
{
super();
}
@BeforeMethod
public void SetUp() throws Throwable
{
Initalization();
loginpage = new LoginPage();
dashboardpage = new DashboardPage();
}
@Test(priority = 0)
public void VerifyTitleTest()
{
//logger = reports.createTest("Verify Title");
String PageTitle = loginpage.VerifyPageTitle();
}
@Test(priority = 1)
public void VerifyLogoTest()
{
boolean PLogo = loginpage.VerifyLogo();
Assert.assertEquals(PLogo , true);
logger.log(Status.PASS, "Verified logo");
}
@Test(priority = 2)
public void LoginPageTest() throws Throwable
{
//logger = reports.createTest("Verify Login");
dashboardpage = loginpage.Login(prop.getProperty("username"), prop.getProperty("password"));
System.out.println("Logged in Successfully");
logger.log(Status.PASS, "Logged in successfully");
}
}