top of page

Types of Framework and Sample code using Page Object Model (POM) and Page Factory (PF)

In this blog you can find information on What , Why and How to use the following in Selenium Project .

Topics Covered

  • Framework

  • PageObjects

  • PageFactory

  • Pom.xml

  • Maven Dependencies

What is a Selenium framework?

Selenium framework is a code structure for making code maintenance simpler, and code readability better. A framework involves breaking the entire code into smaller pieces of code, which test a particular functionality.

The code is structured such that, the “data set” is separated from the actual “test case” which will test the functionality of the web application.

Benefits of Selenium framework

  • Increased code reusage

  • Improved code readability

  • Higher portability

  • Reduced script maintenance

Customized /User Defined Framework

*Modular Driven Framework -

Modular framework is like creation of small, independent scripts that represents modules, sections and functions of the application under test. Testers use Modular testing framework to divide an application into multiple modules and create test scripts individually.

*Data- driven Framework - Taking data from Excel

A Data Driven Framework in Selenium is a technique of separating the “data set” from the actual “test case” (code). Since the test case is separated from the data set, one can easily modify the test case of a particular functionality without making changes to the code.

*Keyword driven Framework - Call functions by Keywords

A keyword driven framework in Selenium is a testing approach that uses a table of keywords to represent the actions and inputs for each test case. The test cases are then constructed by calling the keywords in a specific sequence to perform the desired testing steps.

*Hybrid Framework -

Hybrid Driven Framework in Selenium is a mix of both the Data-Driven and Keyword Driven frameworks. In this case, the keywords as well as the test data, are externalized. Keywords are stored in a separate Java class file and test data can be maintained in a Properties file or an Excel file.

What is the difference between Page Object Model (POM) and Page Factory:

Page Object

  • Is a class that represents a web page and hold the functionality and members.

  • Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements.

  • It helps reduce code duplication and improves test case maintenance.

  • In Page Object Model, consider each web page of an application as a class file.

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.

  • Page Factory is a class provided by Selenium WebDriver to support Page Object Design patterns.

  • In Page Factory, testers use @FindBy annotation.

  • The initElements method is used to initialize web elements.

  • @FindBy: An annotation used in Page Factory to locate and declare web elements using different locators.

What is the use of POM?

  • Object repository is independent of test cases.

  • 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.

1.Using FindBy



public class Login_pageObjects 
    @FindBy(how=How.XPATH, using="//input[@id='Email']") 
        public static WebElement username;
        public static WebElement password;
    @FindBy(how=How.XPATH,using="//button[normalize-space()='Log in']")
        public static  WebElement loginButton;

2.Using By

import org.openqa.selenium.By; 
public class Login_pageObjects 
       By loginButton=By.xpath("//button[@type='submit']");

Sample Code for Orange HRM Using POM

public class OrangeHRM_POM {
		WebDriver driver;
		String URL="";	
// 1.*************************************
		By logIn=By.xpath("//button[@type='submit']");
// 2.*******************************************
		By info=By.xpath("//*[@id='app']//ul/li[6]/a");
		By addContact=By.linkText("Contact Details");
		By street1=By.xpath("//*[@id='app']//form/div[1]/div/div[1]/div/div[2]/input");
		By street2=	By.xpath("//*[@id='app']//form/div[1]/div/div[2]/div/div[2]/input");
		By city=By.xpath("//*[@id='app']//form/div[1]/div/div[3]/div/div[2]/input");
		By state=By.xpath("//*[@id='app']//form/div[1]/div/div[4]/div/div[2]/input");
		By zip=By.xpath("//*[@id='app']//form/div[1]/div/div[5]/div/div[2]/input");
		By telephone=By.xpath("//*[@id='app']//form/div[2]/div/div[1]/div/div[2]/input");
		By saveInfo=By.xpath("//*[@id='app']//form/div[4]/button");

// launching  browser   
		public void launch_Browser() {
			//1.Launch the application
			driver=new ChromeDriver();	
// 1. Launch the below application
//and login with give credentials 			
		public void loginPage()  {
//2. Navigate to My info - > Contact Details, enter contact details and press save button 		
		public void myInfo() throws InterruptedException  {	
		driver.findElement(street1).sendKeys(Keys.CONTROL + "A");
		driver.findElement(street1).sendKeys(Keys.CONTROL + "X");
		driver.findElement(street2).sendKeys(Keys.CONTROL + "A");
		driver.findElement(street2).sendKeys(Keys.CONTROL + "X");
		driver.findElement(city).sendKeys(Keys.CONTROL + "A");
		driver.findElement(city).sendKeys(Keys.CONTROL + "X");
		driver.findElement(state).sendKeys(Keys.CONTROL + "A");
		driver.findElement(state).sendKeys(Keys.CONTROL + "X");
		driver.findElement(zip).sendKeys(Keys.CONTROL + "A");
		driver.findElement(zip).sendKeys(Keys.CONTROL + "X");
		driver.findElement(telephone).sendKeys(Keys.CONTROL + "A");
		driver.findElement(telephone).sendKeys(Keys.CONTROL + "X");
		driver.findElement(saveInfo).click()	;		

Difference between POM and PF


Webelement Locators                   
Using Elements In Method 


Webelement Locators 
public static WebElement e_Mail;    
publicstatic WebElement pass_Word; 
Using page Factory to use all webelements 
PageFactory.initElements(driver, Juice_Shop_PF.class);  // for null exception
Using Elements in method


public void login() throws InterruptedException
	 WebDriver driver=new ChromeDriver();
	 PageFactory.initElements(driver, Login_pageObjects.class);  // for null exception 

Orange HRM PF Model

1.Page Objects class

public class OrangeHRM_PF_Objects {
		WebDriver driver;
		String URL="";
		@FindBy(how=How.NAME, using="username")
		public static WebElement userName;
		public static WebElement passWord;
		public static WebElement logIn;

2.Test Case

public class OrangeHRM_PF_TestCase {
	WebDriver driver;
	String URL="";

// ********************  browser   **********************************
	public void launch_Browser() {
		driver=new ChromeDriver();	
	public void loginPage() throws InterruptedException  {
		PageFactory.initElements(driver, OrangeHRM_PF_Objects.class);  // for null exception 

What does Maven stand for?

The Mars Atmosphere and Volatile Evolution (MAVEN) mission was selected as part of NASA's now-canceled Mars Scout Program to explore the atmosphere and ionosphere of the planet and how they interact with the Sun and solar wind.

What is POM XML in Selenium?

  • Maven project provide POM.xml file by default.

  • Maven project is controlled by pom.xml file

  • By default Maven project gives as project structure

  • Pom.xml will add dependencies and plugins

  • Generate Report

  • Document Project

  • Package the project

What does POM stand for?

POM is an acronym for Project Object Model. The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.

It is a single configuration XML file called pom.xml that contains the majority of the information required to build a project.

The role of a POM file is to describe the project, manage dependencies, and declare configuration details that help Maven to build the project.

What is a Maven lifecycle?

The maven builds lifecycle is the tasks performed when the maven build commands are executed. The maven build lifecycle is divided into stages known as build phases. A build phase is made up of objectives. Maven goals are specific tasks that contribute to the creation and management of a project.

Why POM xml is required?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

Each Maven project has Pom.xml with default information about the project


Why we need Maven dependencies?

Maven is chiefly used for Java-based projects, helping to download dependencies, which refers to the libraries or JAR files. The tool helps get the right JAR files for each project as there may be different versions of separate packages.Dependencies are third-party software required by the project.

Why do we need to add dependency? Advantages of Dependency Management It helps when we switch from one version to another. It avoids mismatch of different versions . We only need to write a library name with specifying the version. It is helpful in multi-module projects.

Where does Maven get dependencies from? The Local Repository Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository.

What is the difference between dependency and plugin? A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources).


A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.

<!-- -->

The external jar files that are needed for the project need to be added as dependencies in this pom file. So for example, if you need Selenium JAR files in your project, you will need to add Selenium dependencies in the pom file. Maven then automatically downloads the jar files and adds them to the classpath.


I hope, This article will help you to understand about types of Framework, How to use Page Objects and Page Factory in Framework and the use of Maven Project pom.xml and their dependencies.

You must have got an idea on the topics explained in this blog. Lets explore more and learn New Topics.

Happy Learning

506 views0 comments


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page