All the visible fields that you have annotated will be initialized to the associated web elements.
Which WebElements are filled by PageFactory.initElements?
-
14-01-2022 - |
题
I am trying to use the PageObject
design pattern with my Selenium testing, and I have the following set of Page classes:
- A
PageObject
base class, which keeps track of the WebDriver and site's base URL. It also has privateWebElement
resources 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. UserRolePage
classes which extendPageObject
. Depending on the role of the logged in user, these classes have other privateWebElements
which 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 theUserRolePage
classes. These have their own page-specificWebElements
and 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?
解决方案
不隶属于 StackOverflow