Page Object Model Interview Questions Answers 1) What Is A Page Object Model?
Page Object Model Interview Questions Answers 1) What Is A Page Object Model?
A) Page Object Model is a design pattern which has become popular in test automation for
enhancing test maintenance and reducing code duplication. A page object is an object-oriented
class that serves as an interface to a page of your AUT.
A) Page Object Model in Selenium – Page Object model is an object design pattern in Selenium,
where web pages are represented as classes, and the various elements on the page are defined as
variables on the class.
A) Page Object Model is a Design Pattern which has become popular in Selenium Test
Automation. Page object model (POM) can be used in any kind of framework such as modular,
data-driven, keyword driven, hybrid framework etc.
A) The Page Factory Class is an extension to the Page Object design pattern. It is used to
initialize the elements of the Page Object or instantiate the Page Objects itself. Annotations for
elements can also be created (and recommended) as the describing properties may not always be
descriptive enough to tell one object from the other.
A) Page Factory is an inbuilt page object model concept for Selenium Web Driver, but it is much
optimized. Page Factory can be used in any kind of framework such as Data Driven, Modular or
Keyword Driven. Page Factory gives more focus on how the code is being structured to get the
best benefit out of it.
6) What is the difference between Page Object Model (POM) and Page Factory?
A) 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.
A) Test Class – In Test Class, we will write an actual selenium test script. Here, we call Page
Action and mentioned actions to be
performed on Web Pages. For each page, we can write our own test class for better code
readability. We can write test cases in @Test annotation.
A) Page Action Class – In Page Action Class, we can write all web pages action as per the pages
and functionality. Under Page Action component, for each page in the application, we have
corresponding Page class.
A) Page Factory class is nothing but Object Repository in other term. For each web page, it has
its own Page Object definitions. Each web element should uniquely get identified and should be
defined at class level. We will use Find By annotation and will define web element so that we
will be able to perform actions on them.
10) Can you write sample code for Page Factory Class?
11) Can you write sample code for Page Action Class?
Both POM and Page Factory design patterns are inspired through
Abstraction (i.e the implementation is hidden from other classes)
After that, all the possible scenarios are created as methods in that
class.
Page Factory initializes the elements of the Page Object or instantiates the
Page Objects itself. Annotations for elements can also be produced. It is, in
fact, a better way as the describing properties may not be expressive enough
to differentiate one object from another
If POM is used without a page factory, instead of having to use
‘FindElements,’ @FindBy is used to look for WebElement, and initElements
is used to initialize web elements from the Page Factory class.
@FindBy can accept attributes like tagName, name, partialLinkText ,
linkText, id, className , css, and xpath.
Q.16) What is the major difference between a Page Factory and Page
Object Model (POM)?
A common selenium interview question. A page factory is a method to
initialize web elements within the page object on the creation of the instance.
On the other hand, the page object model is a class that states the web page
and holds its functionalities.
POM does not provide lazy initialization Page Factory does provide lazy
initialization
Page Object Model is a design pattern PageFactory is a class that provides the
implementation of the Page Object Model
design pattern
In POM, one needs to initialize every page In PageFactory, all page objects are
object individually initialized by using
the initElements() method
Page Object Model (POM) is a design principle to manage the test cases and page
objects separately. Framework types like data-driven, behavior-driven, keyword-driven,
etc. can be designed with the page object model.
The main advantage of Page Object Model is that if the UI changes for any page, it
doesn’t require us to change any tests, we just need to change only the code within the
page objects.
improves code readability - Allows us to separate operations and flows in the UI from
Verification
Re-usability of code - a locator or function can be reused in the tests.Eliminate
redundancy – no duplicity of functions or locators.
The Page object is an object-oriented class which acts as an interface for the page of
your Application under test. Page class contains web elements and methods to interact
with web elements. While automating the test cases, we create the object of these Page
Classes and interact with web elements by calling the methods of these classes.
Abstraction:
Both POM and page Factory Design patterns inspired through abstraction.
Interface:
WebDriver driver = new FirefoxDriver();
Inheritance:
Polymorphism:
Encapsulation:
Most frequently used design patterns is POM (Page Object Model). Enhanced POM, also
known as Page Factory can be used which helps you in resolving stale element
exception, also provides cache management. Both POM and Page Factory design
patterns are inspired through Abstraction
Strategy Design pattern
6. What are the Challenges faced while Working with Selenium Automation?