I'm trying to use TestNG and Page Object for my Selenium test. But it fails with java.lang.NullPointerException
error at a line where I'm creating new object of my Page Object Class.
public class TestTitle {
@Test
public void scenario1() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver=new ChromeDriver();
FirstPage fp = new FirstPage(driver);
driver.get("https://www.google.com/");
fp.element.click();
}
}
public class FirstPage {
WebDriver driver;
public FirstPage (WebDriver driver) {
this.driver = driver;
}
public WebElement element = driver.findElement(By.id("hptl"));
}
FAILED: scenario1
java.lang.NullPointerException
at Pages.FirstPage.<init>(FirstPage.java:14)
at Test.TestTitle.scenario1(TestTitle.java:15)
FirstPage.java:14 is public WebElement element = driver.findElement(By.id("hptl"));
TestTitle.java:15 is FirstPage fp = new FirstPage(driver);
Aucun commentaire:
Enregistrer un commentaire