In this post, we will see what is difference between Page Object Model and Page Factory in Selenium WebDriver. This is also a very frequently asked interview question.
Before we proceed. first go through to below posts:
After reading above posts, you must have got differences between Page Factory and Page Object model. We will summarize all points here.
- 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 plain 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.
- Plain 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.
Hope, now you can answer this question well in interview. If you find any other difference, kindly comment. I will include that in post.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning