Friday, 26 January 2018

2. What is the Page Object Model

What is Page Object Model and why we use it

Page Object Model is based on the Page Object design pattern. The Page Object Model dictates that all the web pages of a website need to be treated as individual entities i.e. each page should be represented as classes and the various elements like text boxes, radio buttons, buttons etc are represented as variables in that class. The only difference between a normal variable and these variables is these variables represent proxied objects which can be used in the code to do various operations like button clicks or value selection from dropdowns.

This way, we are creating an object repository in which each variable represents an object. All the variables representing object have to made private to avoid global access. If the variables are not made private, we end up having a glorified webelement store which can be modified by external entities in an inappropriate manner. This helps us to implement encapsulation. 

Next we will go over the framework architecture from a bird's eye view. Let's explore the various sections of the framework. We have two main components i.e. Base Class and TestNG XML

The Base class serves as the parent class for our page object and test classes. The base class will have what is called a Singleton driver object. The Singleton driver is an adaption of the singleton design pattern. Through an entire session of testing, we have just a single instance of the WebDriver to deal with. This eliminates duplicate creation of the various webdriver objects which could get easily scattered throughout the code leading to un-maintenable code. We have creation of the webdriver object only at one place i.e. the Base class. For all the other places, we just retrieve the same instance every time. You may not realize the importance of this right now but later as the framework grows, it will be very simplistic.

Apart from the components mentioned in the diagram below, we will have an Excel utility class, Utilities class and an interface for Global Constants. The Excel utility class will hold generic methods for excel read and write and fetching cell values. The utilities class will have methods for reading and writing text file, taking screenshots etc.




No comments:

Post a Comment