SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
Page Object Model and
Implementation in Selenium
In testing department of today’s IT sector, Automation has a significant role. IT companies
are leaning towards automation testing because there are endless advantages of automating an
application. For programming language, automation gives flexibility. There are distinct types
of frameworks that companies use for automating their applications. Some of which are
mentioned below, and one of which is Page Object Model also popular as POM.
● Page Object Model (POM)
● Hybrid
● Data Driven
● Keyword Driven
POM is a type of framework which is very easy to understand and easy to implement while
making architecture of any automation process. It basically enhances the test maintenance
and reduces the possibility of duplication of code, which is very concerned thing in test
automation. In other words POM is a structured base object repository design.
In POM we create a page class for each corresponding web page in the application. Now, the
page class that we have created contains all the web-elements of that page and also that
methods that we will perform on those web-elements, so the name that we give to a method
should be according to its functionality, for example- for a log-in page, the name of the
method can be login() which only has few elements like user-name, password, log-in button,
forget password link, etc. and methods like passing strings in the field and clicking the
buttons.
For making a robust and easy to maintain framework we use POM with data driven by
collating excel with POM. The best combination would be POM with data driven through
excels and run test cases through TestNG
Below mentioned the flowchart will make it clearer to understand:
Implementation Example in Selenium
1. Create a new package file as Practice; we will be creating different packages for Page
Objects, Utilities, Test Data, Test Cases and Modular actions. It is always recommended
to use this structure, as it is easy to understand, simple to use and easy to maintain.
2. Create a new class file and refer the name to the actual page from the test object. In our
case it is Home Screen and Login Screen.
3. Create a static method for each element in Home Screen. Each method will have an
argument (driver) and returns a value (element).
package Practice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class Home_Screen {
private static WebElement element = null;
public static WebElement MyAccount(WebDriver driver){
element = driver.findElement(By.id(“id”));
return element;
}
public static WebElement LogOut(WebDriver driver){
element = driver.findElement(By.id(“logout”));
return element;
}
}
4.Reason of passing driver as argument selenium is able to locate the element on the browser
(driver). Element is returned so that action can be performed on it.
5.Method is declared as public static so that it can be called in any other method without
creating instance of the class.
6.Follow same rule for creating another class LogIn Screen.
package Practice;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class LogIn_Screen {
private static WebElement element = null;
public static WebElement UserName(WebDriver driver){
element = driver.findElement(By.id(“id”));
return element;
}
public static WebElement Password(WebDriver driver){
element = driver.findElement(By.id(“id”));
return element;
}
public static WebElement LogIn(WebDriver driver){
element = driver.findElement(By.id(“id”));
return element;
}
}
7. Now create a new class which will be our test case, let’s say we are creating it in package
called Framework by name POM.
package Framework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
// Import package pageObject.*
import pageObjects.Home_Screen;
import pageObjects.LogIn_Screen;
public class POM{
private static WebDriver driver = null;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(“http://www.store.demoqa.com”);
// Use page Object library now
Home_Screen.MyAccount(driver).click();
LogIn_Screen.UserName(driver).sendKeys(“testuser_1”);
LogIn_Screen.Password(driver).sendKeys(“Test@123”);
LogIn_Screen.LogIn(driver).click();
System.out.println(” Login Successfully, now it is the time to Log Off buddy.”)
Home_Screen.LogOut(driver).click();
driver.quit();
}
}
8.You will notice that once you type HomeScreen in your test script and the moment you
press dot, all the methods in the Home Page will display. We can expose methods in order to
reduce duplicated code. We are able to call these method multiple times. This will ensure a
better maintainable test code, because we only have to make adjustments and improvements
in one particular place.
**Implementation reference is taken from: toolsqa.com.

More Related Content

What's hot (20)

PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PDF
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
PDF
Selenium IDE LOCATORS
Mindfire Solutions
 
PDF
What's new in selenium 4
Knoldus Inc.
 
PPT
testng
harithakannan
 
PPT
Selenium
Adam Goucher
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PPT
Selenium Concepts
Swati Bansal
 
PPT
Java Basics for selenium
apoorvams
 
PPTX
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
PPTX
Selenium test automation
Srikanth Vuriti
 
PPTX
Introduction to Spring Framework
Serhat Can
 
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
ODP
BDD with Cucumber
Knoldus Inc.
 
PPTX
Test automation using selenium
Cynoteck Technology Solutions Private Limited
 
PDF
Web automation using selenium.ppt
Ana Sarbescu
 
PPTX
Robot framework
boriau
 
PDF
Test Automation
rockoder
 
PPTX
Selenium WebDriver
Yuriy Bezgachnyuk
 
PDF
Latest Selenium Interview Questions And Answers.pdf
Varsha Rajput
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Xpath in Selenium | Selenium Xpath Tutorial | Selenium Xpath Examples | Selen...
Edureka!
 
Selenium IDE LOCATORS
Mindfire Solutions
 
What's new in selenium 4
Knoldus Inc.
 
Selenium
Adam Goucher
 
Spring Framework - Core
Dzmitry Naskou
 
Selenium Concepts
Swati Bansal
 
Java Basics for selenium
apoorvams
 
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
Selenium test automation
Srikanth Vuriti
 
Introduction to Spring Framework
Serhat Can
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
BDD with Cucumber
Knoldus Inc.
 
Test automation using selenium
Cynoteck Technology Solutions Private Limited
 
Web automation using selenium.ppt
Ana Sarbescu
 
Robot framework
boriau
 
Test Automation
rockoder
 
Selenium WebDriver
Yuriy Bezgachnyuk
 
Latest Selenium Interview Questions And Answers.pdf
Varsha Rajput
 

Similar to Page Object Model and Implementation in Selenium (20)

PDF
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
PDF
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
PDF
Advanced Techniques to Build an Efficient Selenium Framework
digitaljignect
 
PDF
Ui automation
test test
 
PPT
Selenium training in chennai
Thecreating Experts
 
PDF
Web UI test automation instruments
Artem Nagornyi
 
PDF
Automation Abstraction Layers: Page Objects and Beyond
Alan Richardson
 
PDF
Selenium course training institute ameerpet hyderabad – Best software trainin...
Sathya Technologies
 
PDF
Selenium course training institute ameerpet hyderabad
Sathya Technologies
 
ODP
FluentSelenium Presentation Code Camp09
Pyxis Technologies
 
PDF
Getting Started with Selenium
Dave Haeffner
 
PPTX
Web UI Tests: Introduce UI tests using Selenium
Peyman Fakharian
 
PDF
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Sargis Sargsyan
 
PDF
Gilt Groupe's Selenium 2 Conversion Challenges
Sauce Labs
 
PDF
Selenium Design Patterns And Best Practices Dima Kovalenko
njamberudito
 
PDF
Test automation & Seleniun by oren rubin
Oren Rubin
 
PPTX
BDD approach with Selenium RC
Mykola Kolisnyk
 
DOCX
Selenium webdriver course content rakesh hansalia
Rakesh Hansalia
 
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
Advanced Techniques to Build an Efficient Selenium Framework
digitaljignect
 
Ui automation
test test
 
Selenium training in chennai
Thecreating Experts
 
Web UI test automation instruments
Artem Nagornyi
 
Automation Abstraction Layers: Page Objects and Beyond
Alan Richardson
 
Selenium course training institute ameerpet hyderabad – Best software trainin...
Sathya Technologies
 
Selenium course training institute ameerpet hyderabad
Sathya Technologies
 
FluentSelenium Presentation Code Camp09
Pyxis Technologies
 
Getting Started with Selenium
Dave Haeffner
 
Web UI Tests: Introduce UI tests using Selenium
Peyman Fakharian
 
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Sargis Sargsyan
 
Gilt Groupe's Selenium 2 Conversion Challenges
Sauce Labs
 
Selenium Design Patterns And Best Practices Dima Kovalenko
njamberudito
 
Test automation & Seleniun by oren rubin
Oren Rubin
 
BDD approach with Selenium RC
Mykola Kolisnyk
 
Selenium webdriver course content rakesh hansalia
Rakesh Hansalia
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Ad

More from Zoe Gilbert (20)

PDF
SAP HANA Implementation A Complete Guide.pdf
Zoe Gilbert
 
PDF
HIPAA Compliance Testing In Software Applications.pdf
Zoe Gilbert
 
PDF
Checklist For Modernizing Your Legacy Application.pdf
Zoe Gilbert
 
PDF
Ad Hoc Testing: Everything You Need To Know
Zoe Gilbert
 
PDF
Eliminate OTT Platform Flaws with Quality Engineering.pdf
Zoe Gilbert
 
PDF
Best Tools for Website Accessibility Testing in 2022.pdf
Zoe Gilbert
 
PDF
What are the Advantages and Disadvantages of Microservices?
Zoe Gilbert
 
PDF
Embedded Testing Vs Software Testing – Key Difference.pdf
Zoe Gilbert
 
PDF
Why is Low Code Automation Testing Gaining Popular.pdf
Zoe Gilbert
 
PDF
Logistics Automation to Strengthen Process Efficiency.pdf
Zoe Gilbert
 
PDF
Accelerating Digital Transformation in the BFSI Sector.pdf
Zoe Gilbert
 
PDF
Hyperautomation.pdf
Zoe Gilbert
 
PDF
What is the Right Approach to QA Outsourcing.pdf
Zoe Gilbert
 
PDF
AI in Cloud Computing
Zoe Gilbert
 
PDF
Boast the Potential of DevOps with CI CD
Zoe Gilbert
 
PDF
What is Sanity Testing.pdf
Zoe Gilbert
 
PDF
Tackle Business Risks with Continuous Testing.pdf
Zoe Gilbert
 
PDF
Guide to Successful AI.pdf
Zoe Gilbert
 
PDF
Top Software Testing Models for Customer Satisfaction.pdf
Zoe Gilbert
 
PDF
Compliance testing or conformance testing
Zoe Gilbert
 
SAP HANA Implementation A Complete Guide.pdf
Zoe Gilbert
 
HIPAA Compliance Testing In Software Applications.pdf
Zoe Gilbert
 
Checklist For Modernizing Your Legacy Application.pdf
Zoe Gilbert
 
Ad Hoc Testing: Everything You Need To Know
Zoe Gilbert
 
Eliminate OTT Platform Flaws with Quality Engineering.pdf
Zoe Gilbert
 
Best Tools for Website Accessibility Testing in 2022.pdf
Zoe Gilbert
 
What are the Advantages and Disadvantages of Microservices?
Zoe Gilbert
 
Embedded Testing Vs Software Testing – Key Difference.pdf
Zoe Gilbert
 
Why is Low Code Automation Testing Gaining Popular.pdf
Zoe Gilbert
 
Logistics Automation to Strengthen Process Efficiency.pdf
Zoe Gilbert
 
Accelerating Digital Transformation in the BFSI Sector.pdf
Zoe Gilbert
 
Hyperautomation.pdf
Zoe Gilbert
 
What is the Right Approach to QA Outsourcing.pdf
Zoe Gilbert
 
AI in Cloud Computing
Zoe Gilbert
 
Boast the Potential of DevOps with CI CD
Zoe Gilbert
 
What is Sanity Testing.pdf
Zoe Gilbert
 
Tackle Business Risks with Continuous Testing.pdf
Zoe Gilbert
 
Guide to Successful AI.pdf
Zoe Gilbert
 
Top Software Testing Models for Customer Satisfaction.pdf
Zoe Gilbert
 
Compliance testing or conformance testing
Zoe Gilbert
 
Ad

Recently uploaded (20)

PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 

Page Object Model and Implementation in Selenium

  • 1. Page Object Model and Implementation in Selenium In testing department of today’s IT sector, Automation has a significant role. IT companies are leaning towards automation testing because there are endless advantages of automating an application. For programming language, automation gives flexibility. There are distinct types of frameworks that companies use for automating their applications. Some of which are mentioned below, and one of which is Page Object Model also popular as POM. ● Page Object Model (POM) ● Hybrid ● Data Driven ● Keyword Driven POM is a type of framework which is very easy to understand and easy to implement while making architecture of any automation process. It basically enhances the test maintenance and reduces the possibility of duplication of code, which is very concerned thing in test automation. In other words POM is a structured base object repository design. In POM we create a page class for each corresponding web page in the application. Now, the page class that we have created contains all the web-elements of that page and also that methods that we will perform on those web-elements, so the name that we give to a method should be according to its functionality, for example- for a log-in page, the name of the method can be login() which only has few elements like user-name, password, log-in button, forget password link, etc. and methods like passing strings in the field and clicking the buttons.
  • 2. For making a robust and easy to maintain framework we use POM with data driven by collating excel with POM. The best combination would be POM with data driven through excels and run test cases through TestNG Below mentioned the flowchart will make it clearer to understand: Implementation Example in Selenium 1. Create a new package file as Practice; we will be creating different packages for Page Objects, Utilities, Test Data, Test Cases and Modular actions. It is always recommended to use this structure, as it is easy to understand, simple to use and easy to maintain. 2. Create a new class file and refer the name to the actual page from the test object. In our case it is Home Screen and Login Screen. 3. Create a static method for each element in Home Screen. Each method will have an argument (driver) and returns a value (element). package Practice; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;
  • 3. import org.openqa.selenium.WebElement; public class Home_Screen { private static WebElement element = null; public static WebElement MyAccount(WebDriver driver){ element = driver.findElement(By.id(“id”)); return element; } public static WebElement LogOut(WebDriver driver){ element = driver.findElement(By.id(“logout”)); return element; } } 4.Reason of passing driver as argument selenium is able to locate the element on the browser (driver). Element is returned so that action can be performed on it. 5.Method is declared as public static so that it can be called in any other method without creating instance of the class. 6.Follow same rule for creating another class LogIn Screen. package Practice; import org.openqa.selenium.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class LogIn_Screen { private static WebElement element = null; public static WebElement UserName(WebDriver driver){ element = driver.findElement(By.id(“id”)); return element; }
  • 4. public static WebElement Password(WebDriver driver){ element = driver.findElement(By.id(“id”)); return element; } public static WebElement LogIn(WebDriver driver){ element = driver.findElement(By.id(“id”)); return element; } } 7. Now create a new class which will be our test case, let’s say we are creating it in package called Framework by name POM. package Framework; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; // Import package pageObject.* import pageObjects.Home_Screen; import pageObjects.LogIn_Screen; public class POM{ private static WebDriver driver = null; public static void main(String[] args) { driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(“http://www.store.demoqa.com”); // Use page Object library now Home_Screen.MyAccount(driver).click();
  • 5. LogIn_Screen.UserName(driver).sendKeys(“testuser_1”); LogIn_Screen.Password(driver).sendKeys(“Test@123”); LogIn_Screen.LogIn(driver).click(); System.out.println(” Login Successfully, now it is the time to Log Off buddy.”) Home_Screen.LogOut(driver).click(); driver.quit(); } } 8.You will notice that once you type HomeScreen in your test script and the moment you press dot, all the methods in the Home Page will display. We can expose methods in order to reduce duplicated code. We are able to call these method multiple times. This will ensure a better maintainable test code, because we only have to make adjustments and improvements in one particular place. **Implementation reference is taken from: toolsqa.com.