Chapter 8. Using the Page Object Model

In this chapter, we will cover the following topics:

  • Using the PageFactory class for exposing the elements on a page
  • Using the PageFactory class for exposing an operation on a page
  • Using the LoadableComponent class
  • Implementing nested Page Object instances
  • Implementing the Page Object model in .NET
  • Implementing the Page Object model in Python
  • Implementing the Page Object model in Ruby using the page-object gem

Introduction

Developing a maintainable automation code is one of the keys to a successful test-automation project. Test-automation code should to be treated as production code, and similar standards and patterns should be applied while developing this code.

While developing Selenium WebDriver tests, we can use the Page Object model pattern. This pattern helps enhance the tests by making them highly maintainable, reducing the code duplication, building a layer of abstraction, and hiding the inner implementation from tests.

By applying object-oriented development principles, we can develop a class that serves as an interface to a web page in the application, modeling its properties and behavior. This helps in creating a layer of separation between the test code and the code specific to the page by hiding technical implementations such as locators used to identify elements on the page, layout, and so on. The Page Object design pattern provides an interface where a test can operate on that page in a manner similar to the user accessing the page, but by hiding its internals. For example, if we build a Page Object for a login page, then it will provide a method to log in, which will accept the username and password and take the user to the home page of the application. The test need not worry about how input controls are used for the login page, their locator details, and so on. It will instantiate the login page object and call the login method by passing the username and password. Tests should use objects of a page at a high level, where any change in layout or attributes used for the fields in the underlying page should not break the test.

This chapter covers recipes to build tests using the Page Object model and related designs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.55.198