Skip to main content

Page Object Model && Page Factory


Page Object Model Design Pattern (POM):

Page Object Model is a Design Pattern which has become popular in Selenium Test Automation. It is widely used design pattern in Selenium for enhancing test maintenance and reducing code duplication. In Selenium all we are doing is finding elements and filling values for those elements.
For small script it’s easy to maintain. But with time test suite will grow. As we add more and more lines to our code, things become tough.The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, we need to change all 10 scripts. This is time consuming and error prone.
A better approach to script maintenance is to create a separate class file which would find web elements, fill them or verify them. This class can be reused in all the scripts using that element. In future, if there is a change in the web element, we need to make the change in just 1 class file and not 10 different scripts. This approach is called Page Object Model(POM). It helps make the code more readable, maintainable, and reusable. Under this model, for each web page in the application, there should be corresponding page class.This Page class will find the Web Elements of that web page and also contains Page methods which perform operations on those Web Elements.

Advantages of Page Object Model Framework

Code re-usability – We could achieve code re-usability by writing the code once and use it in different tests.
Code maintainability – There is a clean separation between test code and page specific code such as locators and layout which becomes very easy to maintain code. Code changes only on Page Object Classes when a UI change occurs. It enhances test maintenance and reduces code duplication.
Object Repository – Each page will be defined as a java class. All the fields in the page will be defined in an interface as members. The class will then implement the interface.
Readability – Improves readability due to clean separation between test code and page specific code

Page Factory

‘Page Object Model’ is a way of representing an application in a test framework. For every ‘page’ in the application, we create a Page Object to reference the ‘page’ whereas a ‘Page Factory’ is one way of implementing the ‘Page Object Model’.
The PageFactory Class in Selenium is an extension to the Page Object design pattern. It is used to initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for elements can also be created (and recommended) as the describing properties may not always be descriptive enough to tell one object from the other.
It is used to initialize elements of a Page class without having to use ‘FindElement’ or ‘FindElements’. Annotations can be used to supply descriptive names of target objects to improve code readability.

Difference between Page Object Model (POM) and Page Factory

Page Object is a class that represents a web page and hold the functionality and members.
Page Factory is a way to initialize the web elements we want to interact with within the page object when we create an instance of it.




Comments

Popular posts from this blog

JIRA OverView

What is JIRA? JIRA is a project management tool used for issues and bugs tracking system for all types of testing.The JIRA dashboard consists of many useful functions and features which make handling of issues easy. The following points explain some interesting details of JIRA. • JIRA is an incident management tool. • JIRA is not an acronym, the name 'JIRA' comes from the Japanese word 'Gojira' • JIRA is developed by Australian Company Atlassian • JIRA is a platform independent tool; it can be used with any OS. • JIRA is multi-lingual tool − English, French, German, Japanese, Spanish, etc. • JIRA can be integrated with many other tools like GitHub, Team Foundation Software and many more. • JIRA is a commercial tool and available as a Trial version for a limited time. • To utilize JIRA services, a license is required. Features: JIRA is one the best product management tool which includes: Issue tracking & management: A software application that allows to