I am trying to use the PageObject design pattern with my Selenium testing, and I have the following set of Page classes:
- A
PageObjectbase class, which keeps track of the WebDriver and site’s base URL. It also has privateWebElementresources which show up on every page in the site, e.g. the menu bar and side bar links. There are public methods to access these resources, e.g. to login and logout. UserRolePageclasses which extendPageObject. Depending on the role of the logged in user, these classes have other privateWebElementswhich persist on each page once the user is logged in. There are public methods to access these resources as well.- specific pages (e.g.
UserLandingPage) which extend theUserRolePageclasses. These have their own page-specificWebElementsand actions.
When I create a new UserLandingPage using the method:
UserLandingPage userLanding = PageFactory.initElements(driver, UserLandingPage.class);
which WebElements get populated? Just the ones which are visible to the UserLandingPage class, or does PageFactory somehow look at all the base classes and populate those WebElements as well?
All the visible fields that you have annotated will be initialized to the associated web elements.