O'Reilly logo

Selenium WebDriver Practical Guide by Satya Avasarala

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What is the PageObject pattern?

Whenever we are designing an automation framework for testing web applications, we have to accept the fact that the target application and its elements are bound to change. An efficient framework is one that needs minimal refactoring to adapt to new changes in the target application. Let us try to build the preceding test scenarios into the PageObject design pattern model. Let us first start building a PageObject for the login page. This should look as shown in the following code:

public class AdminLoginPage {
    WebDriver driver;
    WebElement email;
   WebElement password;
    WebElement submit; public AdminLoginPage(WebDriver driver){ this.driver = driver; driver.get("http://pageobjectpattern.wordpress.com/wp-admin"); email ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required