I am getting java.lang.NullPointerException while executing my test case

  • I am getting java.lang.NullPointerException while executing my test case , I am using Page Object Modle with PageFactory ,following are the code snippets

    TestBase Class:

    ackage com.base;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import pagefactory.Scorex_LoginPage;
    import pagefactory.Scorex_HomePage;
    public class TestBase {
           protected WebDriver driver;
           protected String baseUrl = "http://scorex.domain.com/";
           protected Scorex_LoginPage objLogin;
           protected Scorex_HomePage objHome;
           public void initializeBrowser() {
                 driver = new FirefoxDriver();
                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
           public void closeBrowser(){

    Test Case Class:

    package tests;
    import org.testng.Assert;
    import org.testng.annotations.Test;
    import com.base.TestBase;
    public class Scorex_LoginTestCases extends TestBase{
        @Test(priority=1) //TC01
        public void Scorex_valid_email_password()
            objLogin.loginScoreAs("superadmin@domain.com", "superadmin");
            String DashboardUserName = objHome.getHomePageUserName();
            Assert.assertTrue(DashboardUserName.contains("Super Admin"));

  • On the Scorex_LoginTestCases (Btw, we do not use underscore in names in Java (See conventions), the objects objLogin and objHome are not initialized.

    On the TestBase, you should initialize them using the PageFactory's method initElements. You can see a sample here.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2