SlideShare a Scribd company logo
2
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.
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPTX
API Testing for everyone.pptx
Pricilla Bilavendran
 
PPT
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
PPTX
Automated testing using Selenium & NUnit
Alfred Jett Grandeza
 
PPTX
Data driven Automation Framework with Selenium
Edureka!
 
PPTX
Selenium WebDriver
Yuriy Bezgachnyuk
 
PPTX
Cypress Automation
Susantha Pathirana
 
PPTX
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
PPT
Test automation process
Bharathi Krishnamurthi
 
PPTX
Api Testing
Vishwanath KC
 
PPTX
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Pankaj Dubey
 
PDF
SELENIUM PPT.pdf
RebelSnowball
 
PDF
Web automation using selenium.ppt
Ana Sarbescu
 
PPT
Test Automation Framework Designs
Sauce Labs
 
PPTX
Selenium- A Software Testing Tool
Zeba Tahseen
 
PPT
Hybrid Automation Framework Development introduction
Ganuka Yashantha
 
PPTX
TestNG Framework
Levon Apreyan
 
PPT
Automation With A Tool Demo
Nivetha Padmanaban
 
PDF
Selenium WebDriver with C#
srivinayak
 
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Introduction to Selenium Web Driver
Return on Intelligence
 
API Testing for everyone.pptx
Pricilla Bilavendran
 
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Automated testing using Selenium & NUnit
Alfred Jett Grandeza
 
Data driven Automation Framework with Selenium
Edureka!
 
Selenium WebDriver
Yuriy Bezgachnyuk
 
Cypress Automation
Susantha Pathirana
 
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
Test automation process
Bharathi Krishnamurthi
 
Api Testing
Vishwanath KC
 
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Pankaj Dubey
 
SELENIUM PPT.pdf
RebelSnowball
 
Web automation using selenium.ppt
Ana Sarbescu
 
Test Automation Framework Designs
Sauce Labs
 
Selenium- A Software Testing Tool
Zeba Tahseen
 
Hybrid Automation Framework Development introduction
Ganuka Yashantha
 
TestNG Framework
Levon Apreyan
 
Automation With A Tool Demo
Nivetha Padmanaban
 
Selenium WebDriver with C#
srivinayak
 

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

PPTX
Selenium.pptx
Pandiya Rajan
 
PDF
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
PDF
Introduction to Selenium and Test Automation
Ahmed Mubbashir Khan
 
PPTX
Using Page Objects
Getch88
 
PPTX
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
PDF
Selenium with testng and eclipse ide
Testertester Jaipur
 
PPT
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
PPTX
Selenium Automation in Java Using HttpWatch Plug-in
Sandeep Tol
 
PDF
Uploading files using selenium web driver
Pankaj Biswas
 
PPT
Selenium
Sun Technlogies
 
PPTX
Selenium withnet
Vlad Maniak
 
PPTX
Protractor framework architecture with example
shadabgilani
 
PPTX
Qa process
Aila Bogasieru
 
PDF
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Ondřej Machulda
 
PPTX
Qa process
Aila Bogasieru
 
PPTX
Test automation
Kaushik Banerjee
 
PPT
Test Automation Framework Development Introduction
Ganuka Yashantha
 
PPTX
Codeception
少東 張
 
PPT
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
Selenium.pptx
Pandiya Rajan
 
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
Introduction to Selenium and Test Automation
Ahmed Mubbashir Khan
 
Using Page Objects
Getch88
 
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
Selenium with testng and eclipse ide
Testertester Jaipur
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Puneet Kala
 
Selenium Automation in Java Using HttpWatch Plug-in
Sandeep Tol
 
Uploading files using selenium web driver
Pankaj Biswas
 
Selenium
Sun Technlogies
 
Selenium withnet
Vlad Maniak
 
Protractor framework architecture with example
shadabgilani
 
Qa process
Aila Bogasieru
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Ondřej Machulda
 
Qa process
Aila Bogasieru
 
Test automation
Kaushik Banerjee
 
Test Automation Framework Development Introduction
Ganuka Yashantha
 
Codeception
少東 張
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Joe Ferguson
 
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)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 

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.