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 private WebElement 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 extend PageObject. Depending on the role of the logged in user, these classes have other private WebElements 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 the UserRolePage classes. These have their own page-specific WebElements 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?

有帮助吗?

解决方案

All the visible fields that you have annotated will be initialized to the associated web elements.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top