Logical flow for Automating POM, PageFactory framework in selenium
In order to implement POM in we can adopt following project structure:
- Common function Init — which takes care of Browser launch
- Page objects — This defines the Page objects of a page
- Test pages — This Initializes PageFactory for each page and call Page object functions to execute them
PageObject class logic:
Testclass to execute Page Objects:
In above example, we PageFactory Initiates the PageObject webelements by looking for “PageObject Constructor that takes WebDriver” as it’s argument (public SomePage(WebDriver driver)).
If a PageObject do not contains above constructor, we can’t execute PageObject methods.
Sometimes within a Page, we may need to test for webelements of another page. This can be accomplished to initialize the elements of this page as follow:
public BulkCardsMovementFromFilePage(WebDriver driver)
SecondPage seconPageObject = new SecondPage(driver);
//Note, we still need to pass an instance of WebDriver to Initialize elements of second page