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("[email protected]", "superadmin");
        String DashboardUserName = objHome.getHomePageUserName();
        Assert.assertTrue(DashboardUserName.contains("Super Admin"));
  • -1 for the lack of stack trace in question. Stacktrace contains a line number where the error occurs.
    – dzieciou
    Commented Nov 5, 2019 at 5:27

2 Answers 2


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.


If you are using Page Factory we need to initialize the Page Object: You can initialize with the help of below sample code:

driver = new FirefoxDriver();
Scorex_LoginTestCases loginTest = PageFactory.initElements(driver,Scorex_LoginTestCases.class);

And please follow the conventions as method name always starts with a small character and please avoid using underscore. For more information on conventions please click here.

For more information on Page Factory please click here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.