3

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?

Roman C
  • 47,329
  • 33
  • 60
  • 147
rRahkola
  • 33
  • 7

1 Answers1

1

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

jdumonti
  • 26
  • 2
  • So should I not be able to use the `login()` or `logout()` methods from the parent class, since those fields are not visible to the subclass? – rRahkola Jan 24 '13 at 19:19
  • Yes I would expect so. The private WebElements will be accessible through the public login/out methods. I thought it was more of a lazy load where the init happens when you need them. That is why a not found exception is only thrown when you try to access the element and not when the page is instantiated. – jdumonti Jan 25 '13 at 13:07