I have two classes ;
1. Base Class , here I have instantiated all the stuff, example WebDriver driver = new FirefoxDriver();
Similarly I have instantiated Page Factory elements , this looks like this...
package tests;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Base {
public static WebDriver driver = new FirefoxDriver();
public static Base page = PageFactory.initElements(driver,Base.class);
@CacheLookup
@FindBy(id = "user_name")
public static WebElement name;
@CacheLookup
@FindBy(name = "user_email")
public static WebElement lastNameTextbox;
}// class ends
All this inside one class which is Base Class
2.Another Test class
package tests;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class TestPagef extends Base{
@Test
public void testpage() {
driver = new FirefoxDriver();
driver.get(baseUrl);
name.clear();
name.sendKeys("user1");
}
}
After invoking and invoking the browser and getting the baseUrl, it simply gives error
Error that I get on running Test class is :
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:34
I don't understand this error. I have already initialized everything in
Base Class, and used it extended in Test class. So why null
pointer exception.