Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2014 21:42
Show Gist options
  • Save anonymous/8247176 to your computer and use it in GitHub Desktop.
Save anonymous/8247176 to your computer and use it in GitHub Desktop.
/*
error that i got:
java.lang.NullPointerException
at com.mycompany.PageGeneric.login(PageGeneric.java:36)
at com.mycompany.DemoPageFactory.loginTest(DemoPageFactory.java:41)
*/
//this is my page class
public class PageGeneric {
private WebDriver driver;
public PageGeneric(WebDriver driver) {
this.driver = driver;
}
public void open(String siteName) {
driver.manage().window().maximize();
driver.get("http://" + siteName);
}
public PageGeneric loginNC(String userId, String userPassword){
//error says failed on this line - #23
driver.findElement(By.id("username")).sendKeys(userId);
driver.findElement(By.id("password")).sendKeys(userPassword);
driver.findElement(By.id("login")).click();
}
return this;
}
//this is my test class
public class DemoPageFactory {
private WebDriver driver;
//it works fine with local webdriver when i init pagefactory here
PageGeneric pageGeneric = PageFactory.initElements(driver, PageGeneric.class);
@BeforeClass
public void createRemoteDriver() throws Exception {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("platform", "Windows 7");
capabilities.setCapability("version", "10");
this.driver = new RemoteWebDriver(
new URL("url..."),
capabilities);
}
@Test
public void someTest(){
driver.get("some url");
//failed on this line to reference back to my pagegeneric
pageGeneric.loginNC("nameA", "pwdA");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment