-
-
Save jimevans/8247480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
private PageGeneric pageGeneric; | |
@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); | |
// Here is where you instantiate the page object. | |
// It's still done once per class, and yet you are assured | |
// that you have the proper instantiation before calling initElements. | |
this.pageGeneric = PageFactory.initElements(driver, PageGeneric.class); | |
} | |
@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