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

PDF
Page object pattern
Petro Konopelko
 
PPTX
Setting up Page Object Model in Automation Framework
valuebound
 
PDF
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Edureka!
 
PPTX
Selenium ppt
Aneesh Rangarajan
 
PDF
Automation Testing using Selenium
Naresh Chintalcheru
 
PPTX
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPT
Selenium Concepts
Swati Bansal
 
Page object pattern
Petro Konopelko
 
Setting up Page Object Model in Automation Framework
valuebound
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Edureka!
 
Selenium ppt
Aneesh Rangarajan
 
Automation Testing using Selenium
Naresh Chintalcheru
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Introduction to Selenium Web Driver
Return on Intelligence
 
Selenium Concepts
Swati Bansal
 

What's hot (20)

PPTX
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
PPTX
API Automation Testing Using RestAssured+Cucumber
Knoldus Inc.
 
PPTX
Test automation using selenium
Cynoteck Technology Solutions Private Limited
 
PPT
Automation testing
Biswajit Pratihari
 
ODP
Selenium ppt
Anirudh Raja
 
PDF
Web application testing with Selenium
Kerry Buckley
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PPT
Selenium Presentation at Engineering Colleges
Vijay Rangaiah
 
PPTX
Test Automation and Selenium
Karapet Sarkisyan
 
PPTX
An overview of selenium webdriver
Anuraj S.L
 
PPT
Web Test Automation with Selenium
vivek_prahlad
 
PPTX
Selenium WebDriver
Yuriy Bezgachnyuk
 
PDF
Selenium cheat sheet
Sri Priya P Kulkarni
 
PPT
Selenium
conect2krish
 
PDF
SELENIUM PPT.pdf
RebelSnowball
 
PPTX
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Simplilearn
 
PPTX
Selenium-Locators
Mithilesh Singh
 
PPTX
Introduction to selenium
Archana Krushnan
 
PPTX
Katalon Studio - GUI Overview
Katalon Studio
 
PPTX
Selenium
Batch2016
 
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
API Automation Testing Using RestAssured+Cucumber
Knoldus Inc.
 
Test automation using selenium
Cynoteck Technology Solutions Private Limited
 
Automation testing
Biswajit Pratihari
 
Selenium ppt
Anirudh Raja
 
Web application testing with Selenium
Kerry Buckley
 
Selenium Automation Framework
Mindfire Solutions
 
Selenium Presentation at Engineering Colleges
Vijay Rangaiah
 
Test Automation and Selenium
Karapet Sarkisyan
 
An overview of selenium webdriver
Anuraj S.L
 
Web Test Automation with Selenium
vivek_prahlad
 
Selenium WebDriver
Yuriy Bezgachnyuk
 
Selenium cheat sheet
Sri Priya P Kulkarni
 
Selenium
conect2krish
 
SELENIUM PPT.pdf
RebelSnowball
 
Selenium WebDriver Tutorial | Selenium WebDriver Tutorial For Beginner | Sele...
Simplilearn
 
Selenium-Locators
Mithilesh Singh
 
Introduction to selenium
Archana Krushnan
 
Katalon Studio - GUI Overview
Katalon Studio
 
Selenium
Batch2016
 
Ad

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
 

Recently uploaded (20)

PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Doc9.....................................
SofiaCollazos
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Doc9.....................................
SofiaCollazos
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 

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.