What is POM (Page Object Model)? What are its advantages?

Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have its own corresponding page class. The page class is thus responsible for finding the WebElements in that page and then perform operations on those WebElements.

The advantages of using POM are:

  • 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 clean separation between test code and page specific code.