Using the PageFactory class for exposing elements from a page
For implementing the Page Object model in tests, we need to map and create a Page Object class for each page being tested. For example, to test the BMI Calculator application, a BMI Calculator page class will be defined, which will expose the internals of the BMI Calculator page to the test, as shown in following diagram. This is done by using the PageFactory
class of Selenium WebDriver API.
Getting ready
Before exposing the elements of a page, we need to do the following:
Identify locators that will be needed to locate the elements uniquely
Define the structure of the package and classes for objects of the page
How to do it...
Let's implement a Page Object test for the BMI Calculator page using the PageFactory
class with the following steps:
Define and create a package for all the page's objects from the application for logical grouping. For this example,
seleniumcookbook.tests.pageobjects
is created to define all the page's objects...