Hi Raveena, Page Object Model (POM) and Page Factory has following differences:
- A Page Object Model is a test design pattern which says organize page objects as per pages in such a way that scripts and page objects can be differentiated easily. A Page Factory is one way of implementing PageObject Model which is inbuilt in selenium.
- In POM, you define locators using ‘By’ while in Page Factory, you use FindBy annotation to define page objects.
- Page Object Model is a design approach while PageFactory is a class which provides implementation of Page Object Model design approach.
- POM is not optimal as it does not provide lazy initialization while Page Factory provides lazy initialization.
- Plain POM will not help in StaleElementReferecneException while Page Factory takes care of this exception by relocating web element every time whenever it is used.
- In plain page object model, you need to initialize every page object individually otherwise you will encounter NullPointerException while In PageFactory all page objects are initialized (Lazily) by using initElements() method.