Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Selenium Essentials

You're reading from  Selenium Essentials

Product type Book
Published in Mar 2015
Publisher
ISBN-13 9781784394332
Pages 194 pages
Edition 1st Edition
Languages
Author (1):
Prashanth Sams Prashanth Sams
Author Profile Icon Prashanth Sams
Prashanth Sams
Toc

The PageObject pattern


PageObject is an approach widely used in testing to reduce code duplication and increase the reusability of code. It is a design pattern that defines a page using objects. Moreover, the page object provides easy maintenance of code, and the scripts can be read easily anytime by any user. It is a pattern representing an entire page or a portion of the page in an object-oriented behavior.

Let's discuss the PageObject design pattern with an example on the Google web page. To start with the example, let's create a class that emphasizes how to write PageObject methods for a page in detail (GoogleSearchPage.java). The search() and assertTitle()methods let you perform Google searches and to assert the page title on the results page. Here's how we create the aforementioned class for this example:

public class GoogleSearchPage {
  public WebDriver driver;
  private final Wait<WebDriver> wait;

  public GoogleSearchPage(WebDriver driver) {
    this.driver = driver;
    wait...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime