Here is my attempted implementation understanding of PageObjects/Pagefactory as applied to Webdriver:
1. Create the following structure in eclipse
--> com.example.qa.pageobjects
--> LoginPage.java
Every class in this package has something like:
@FindBy(how = How.NAME, using = "logonName")
private WebElement logonNameField;
and the Methods, call Webelement, and call methods on them, like:
logonNameField.sendKeys("username");
Which are called from ScenrioTests.
--> HomePage.java (i go there after i login)
--> Page.java (abstract)
--> com.example.qa.setup
--> Browser.java
--> FirefoxBrowser.java (Code specific to FFox)
--> ChromeBrowser.java (Code Specific to Chrome)
--> com.example.qa.test
--> Scenario1234.java
--> Scenario2345.java
These Scenario Classes instantiate the PageObjects, and Call methods in them, while the Browser setup is only called Once per test run.
Now the question is:
- Should i declare a method like below and call Pagefactory ?
public MyPage method() { Call the Methods like Login() etc return PageFactory.initElements(driver, MDNSLoginPage.class); }
Or, Should i Call the same PageFactory from default Constructor
Is my understanding / implementation correct ?