Hybrid Framework Designing by using(POM, Data Driven and Keyword-Driven) :
Why POM?
Page Object Model Framework has nowadays become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance and reduces the duplication of code.
The main advantage of Page Object Model is that if the UI changes for any page, it doesn’t require us to change any tests, we just need to change only the code within the page objects (Only at one place). Many other tools which are using selenium, are following the page object model.
As you can observe, all we are doing is finding elements and filling values for those elements.
This is a small script. Script maintenance looks easy. But with time test suite will grow. As you add more and more lines to your code, things become tough.
The main problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, you 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.
What is POM?
- Page Object Model is a design pattern to create the Object Repository for web UI elements.
- Under this model, for each web page in the application, there should be a corresponding page class.
- This Page class will find the WebElements of that web page and also contains Page methods which perform operations on those WebElements.

Page Object Model Framework has nowadays become very popular test automation framework in the industry and many companies are using it because of its easy test maintenance and reduces the duplication of code.
The main advantage of Page Object Model is that if the UI changes for any page, it doesn’t require us to change any tests, we just need to change only the code within the page objects (Only at one place). Many other tools which are using selenium, are following the page object model.
As you can observe, all we are doing is finding elements and filling values for those elements.
This is a small script. Script maintenance looks easy. But with time test suite will grow. As you add more and more lines to your code, things become tough.
The main problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, you 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.
What is POM?
- Page Object Model is a design pattern to create the Object Repository for web UI elements.
- Under this model, for each web page in the application, there should be a corresponding page class.
- This Page class will find the WebElements of that web page and also contains Page methods which perform operations on those WebElements.
What is Page Object Model Design Patten (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. Page object model (POM) can be used in any kind of framework such as modular, data-driven, keyword driven, hybrid framework etc. A page object is an object-oriented class that serves as an interface to a page of your Application Under Test(AUT). The tests then use the methods of this page object class whenever they need to interact with the User Interface (UI) of that page. The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently, all changes to support that new UI is located in one place.
- 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. Page object model (POM) can be used in any kind of framework such as modular, data-driven, keyword driven, hybrid framework etc. A page object is an object-oriented class that serves as an interface to a page of your Application Under Test(AUT). The tests then use the methods of this page object class whenever they need to interact with the User Interface (UI) of that page. The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently, all changes to support that new UI is located in one place.
What is Page Factory:
We have seen that "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".
We have seen that "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".
What is the 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 you want to interact with within the page object when you create an instance of it.
Advantages of Page Object Model Framework:
- Code reusability – We could achieve code reusability 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 the clean separation between test code and page specific code.
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 you want to interact with within the page object when you create an instance of it.
Page Factory is a way to initialize the web elements you want to interact with within the page object when you create an instance of it.
Advantages of Page Object Model Framework:
- Code reusability – We could achieve code reusability 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 the clean separation between test code and page specific code.
Creating a Page Object Model with Page Factory in Selenium WebDriver:
Here I will take the Snapdeal Application to showcase implementation of Page Object Model Design Pattern with Page Factory using Selenium with Java.
Scenario: Navigate to snapdeal URL then verify if SignIn button is present or not, search product in product search bar.
Here I will take the Snapdeal Application to showcase implementation of Page Object Model Design Pattern with Page Factory using Selenium with Java.
Scenario: Navigate to snapdeal URL then verify if SignIn button is present or not, search product in product search bar.
No comments:
Post a Comment