Let's take goToTheAboutPage()
. We have refactored it to make it nice and clear, but we now want to abstract things away into a page object to encourage other people to use all that hard work of finding the correct locators. Let's create two page objects called indexPage
and aboutPage
and move our element definitions across into in. We will start off with the index page, as follows:
package com.masteringselenium.page_objects; import org.openqa.selenium.By; public class IndexPage { public static By heading = By.cssSelector("h1"); public static By mainText = By.cssSelector(".col-md-4 > p"); public static By button = By.cssSelector(".btn"); public static By aboutLinkLocator = By.cssSelector(".left-footer > a"); }
Then, we need to create the page object for the about page, as follows:
package com.masteringselenium.page_objects; import org.openqa.selenium.By; public class AboutPage { public static By heading = By.cssSelector("h1"); ...