0% found this document useful (0 votes)
3K views

Page Object Model Interview Questions Answers 1) What Is A Page Object Model?

The document discusses the Page Object Model (POM) design pattern in Selenium test automation. It provides interview questions and answers related to POM. Key points include: - POM is a design pattern that represents web pages as classes and defines page elements as object variables, reducing code duplication. - Page Factory is an enhancement of POM that initializes page objects and elements using annotations like @FindBy. - Test classes call page action classes which contain methods to perform actions on page elements defined in page factory classes. - Advantages of POM include maintainable, readable, and reusable code through separation of elements, actions, and tests across classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

Page Object Model Interview Questions Answers 1) What Is A Page Object Model?

The document discusses the Page Object Model (POM) design pattern in Selenium test automation. It provides interview questions and answers related to POM. Key points include: - POM is a design pattern that represents web pages as classes and defines page elements as object variables, reducing code duplication. - Page Factory is an enhancement of POM that initializes page objects and elements using annotations like @FindBy. - Test classes call page action classes which contain methods to perform actions on page elements defined in page factory classes. - Advantages of POM include maintainable, readable, and reusable code through separation of elements, actions, and tests across classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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.

2) What is a page object model in selenium?

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.

3) Is Page object model a framework?

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.

4) What is the Page Factory Class?

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.

5) What is Page Factory?

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.

7) What is Test Class?

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.

8) What is Page Action Class?

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.

9) What is Page Factory 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?

A) Page Factory Class


@FindBy(xpath=”.//*[@id=’Email’]”)
publicWebElementgmailUserIDWebEdit;

11) Can you write sample code for Page Action Class?

A) Page Action Class


publicclassPageActions_Login
{
WebDriver driver;
PageObjects_Loginpo; // Create Instance to Page Factory
class
publicPageActions_Login(WebDriver driver)
{
this.driver = driver; // set webDriver for current Page
Action
}
}

12) What are the advantages of using page object pattern?

A) ADVANTAGES OF USING PAGE OBJECT PATTERN


Easy to maintain.
Easy readability of scripts – since the test scripts, functions and locators are in different classes it
is easy to walk through the code.
Eliminate redundancy – no duplicity of functions or locators.
Re-usability of code – a locator or function can be reused in the tests.
Reliability.
Test coverage is more since the tests are written program wise.
Performance of each test can be known.
The changes is to be made only in Page Factory class if any locator changes – no need to

Ques5: Which design patterns do you use?


 Most frequently used design patterns is POM (Page Object
Model). In this type of design pattern, one class file is created for
each page of the application under test. In each class, first, an object
repository is created which will have all the WebElements of the
respective page then in the constructor, all these WebElements are
initialized.
 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 (i.e the implementation is hidden from other classes)

 After that, all the possible scenarios are created as methods in that
class.

Ques18: What is POM (Page Object Model)? Is it some framework?


What is it used for?
 POM stands for Page object model, it is not a framework but a
design pattern.

Ques19: What benefit you get by using Page Factory?


 Page Factory is an enhanced way of achieving POM.

Q.7) What is POM? List its advantages?


POM stands for Page Object Model. It is a design pattern for creating an
Object Repository for web UI elements. Every single web page in the
application must have its own corresponding page class, which is in charge of
searching the WebElements in that page and then execute operations on
them.
The advantages of using the Page object model are:
 It makes the code readable by letting developers separate operations
and UI flows from verification. 
 Several tests can use the same Object Repository because it is
independent of Test Cases.
 The code becomes reusable.

Q.8) What is a Page Factory?


Page Factory offers an enhanced method to execute the Page Object Model
by efficiently using the memory, and the execution is done using object-
oriented design. 
 
POM Implementation

With Page Factory Without Page Factory

Uses By() Uses @FindBy()

No imports are required Imports Page factory

No cache storage Cache lookup is faster

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.

Difference Between Page Object Model and Page Factory in Selenium


Page Object Model Page Factory

Finding web elements using By Finding web elements using @FindBy

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

1. What is POM? Advantages of POM?

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.

2. What is Page Factory?


Page Factory is enhancement of POM. Page factory provide the facility to locate and
initialize web elements of an page without using findElement( ) or findElements( )
method of selenium
Page factory provides annotations like @FindBy, @FindAll, which locate the web
element and return the WebElement instance for the same.
These annotations use the attributes for specific locator types like id, name, class name,
CSS, link text, partial link text, class-name, and XPath.
3. How page classes will interact with Web Elements in POM?

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.

4. What are the OOPS Concepts applied in POM?

Abstraction:
Both POM and page Factory Design patterns inspired through abstraction.
Interface:
WebDriver driver = new FirefoxDriver(); 
Inheritance:
Polymorphism:
Encapsulation:

5. What are the Design Pattern used in the Project?

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?

Generally, an automation engineer face is maintaining the code.


If your application is frequently changing html elements of the page and some new
components are being added and so on, this may affect your code, especially locators.
To get rid of these situations we have certain design patterns like POM (Page Object
Model), Page Factory.
One more challenge is while working with Selenium is Synchronization.

You might also like