Implementing Nested Page Object Instances

Pose these questions to the class. The aim is to discuss the complexity of web application structures and web page layouts:

In Modeling a Web Application Using Page Objects, of the current chapter, you learned how to implement the Page Object Model for a web application with one or more web pages. However, applications sometimes involve more complex structures. For example, the home page of an application can consist of many different sections, as illustrated by the following diagram:

Each of these sections can include several elements, with a wide variety of attributes. Although it is possible to write the corresponding Page Object (HomePage class) for a web page like this, it would end up having so many attributes, methods, and lines of code, that the whole purpose of using the Page Object Model—maintainability—would be lost.

A different approach to the POM involves implementing nested Page Object instances. We could model our web page as follows:

  • We could create a Page Object for each section of the home web page. Each of these Page Objects would include, and handle, its own web elements and attributes.
  • We could create a Page Object for the home web page. This Page Object would have the Page Objects that we created for each section of the website as its attributes. In other words, this Page Object would be a wrapper to access the previously created Page Objects. Its attributes would be variables of the Page Objects in the sections, listed as follows:

By modeling the home page sections as Page Objects, we increase the number of classes, but improve the maintainability and reusability. The nested Page Object approach can also be utilized to model pieces of functionality that do not belong to a single page and are available across several pages in the application (such as the sign-in button or a search field).

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

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