Introduction:
Before moving to Page object Model in Selenium let us get an idea of Design Pattern.
Design Pattern:
A Design pattern is a generic solution to a common software design/architecture problem. Implementation of these design patterns leads to inclusion of best practices and best solution, evolved over the time by others while working with similar problems.
Page Object Model is a design pattern to create Object Repository for web User Interface elements.Under this model, for each web page in the application, there should be 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. POM has nowadays become popular test automation design pattern around the testing industry. POM facilitates as to concentrate on testing the AUT rather than fixing the automation suite (the changed objects) to perform the test. In POM the Object information is managed outside the test script, thus making easy to understand the test script.
Advantages Of POM:
- It makes ease in maintaining the code (flow in the UI is separated from verification).
- Makes code readable (Methods get more realistic names).
- Makes the code reusable (object repository is independent of test cases).
- The Code becomes less and optimized.
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’.
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.