what is pom in selenium

1 year ago 62
Nature

In Selenium, Page Object Model (POM) is a design pattern that creates an object repository for storing all web elements, making it easier to maintain test cases and reduce code duplication. Page Factory is a factory class in Selenium that optimizes test instances created using POM. It allows annotations to build up a set of web elements, making it faster to create initial page objects. The advantages of using POM and Page Factory in Selenium include:

  • Code becomes less and optimized because of the reusable page methods in the POM classes.
  • Methods get more realistic names which can be easily mapped with the operation happening in UI.
  • Easy maintenance: POM is useful when there is a change in a UI element or a change in action. It helps identify the page or screen to be modified, making test cases easy to maintain and reducing errors.
  • Lazy initialization: AjaxElementLocatorFactory is a lazy load concept in Page Factory. This is used to identify web elements only when used in any operation or activity.

To implement POM and Page Factory in Selenium, one can create a separate class file for each web page, which consists of different web elements present on the web page. The test scripts then use these elements to perform different actions. PageFactory.initElements(WebDriver driver, java.lang.Class.pageObjectClass) is used to initialize the Page Factory.