Sunteți pe pagina 1din 19

POM and Page Factory in Selenium

Best Approach for Script Maintenance


Agenda
01 UI Automation in Selenium Webdriver

02 POM

03 Page Factory

04 Advantages of Using POM


UI Automation in Selenium Webdriver

01 What is Selenium Webdriver 02 Webdriver Workflow

How do web driver achieve UI


03 Automation
01 What is Selenium Webdriver

Selenium Webdriver is collection of APIs which are used to automate


web application UIs, thus it helps for UI test automation

Taken the compatibility seriously- selenium works with many browsers,


operating systems, multiple languages and testing frameworks
02 Workflow
03 How do Webdriver achieve UI Automation

Locating UI Elements

Webdriver UI Automation

Perform Actions
Locating UI Elements

1. By ID

2. By Class Name

3. By Tag Name

4. By Name

5. By LinkText

6. By Partial LinkText

7. By CSS Selector

8. By Xpath
Example : Google search automation
POM

01 Why POM 02 What is POM

03 How to implement POM


01 Why POM
02 What is POM

• Page Object Model is a design pattern to create Object Repository for web UI
elements.

• Under this model, for each web page in the application, there should be
corresponding page class.

• This Page class will find the WebElements of that web page and also contains
Page methods which perform operations on those WebElements.

• Name of these methods should be given as per the task they are performing, i.e., if
a loader is waiting for the payment gateway to appear, POM method name can be
waitForPaymentScreenDisplay().
Project Folder structure look like...
03 How to implement POM
Project Folder structure for POM look like...
Page Factory

• Page Factory is an inbuilt Page Object Model concept for Selenium WebDriver
but it is very optimized.

• Separates Page Object Repository and Test Methods.

• With the help of PageFactory class, we use annotations @FindBy to find Web
Element. We use initElements method to initialize web elements

• Accepts all the 8 locators as parameter of @FindBy


Advantages of using POM
• Page Object Patten says operations and flows in the UI should be separated from
verification. This concept makes our code cleaner and easy to understand.

• The Second benefit is the object repository is independent of test cases, so we


can use the same object repository for a different purpose with different tools.

• 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. i.e. if after clicking on the button we land on the home page, the
method name will be like 'gotoHomePage()'.
Thank You…

S-ar putea să vă placă și