Web Automation Using Selenium
  • About The Book
  • Selenium
    • Introduction
      • What is testing and why?
      • What is Selenium and Why?
    • Getting Started
      • Audience
      • Prerequisite
      • Set up
      • Getting Started - Hello World..!!
      • What are drivers
    • Locators
      • CSS Selectors
      • XPath Selector
    • WebDriver
      • WebDriver Methods
      • WebDriver Types
    • WebElement(s)
      • WebElement Methods
      • Looping Through WebElements
    • Waits In Selenium
  • TestNG
    • Introduction
    • TestNG Setup
    • First Test Script
    • Some of the features of TestNG
    • TestNG Annotations
      • @Test
      • @DataProvider
  • Maven
    • Introduction
  • Framework Development
    • Introduction
    • Building Framework
      • Technology Stack
      • Page Object Model (POM)
      • Setup
      • What our framework contain
      • Packages
        • Context
        • Factory
        • Listeners
        • Pages
      • Creating first automation test
  • Common Interview Questions
    • Selenium-Related
Powered by GitBook
On this page

Was this helpful?

  1. Framework Development
  2. Building Framework

Page Object Model (POM)

Page Object Model (POM)

Page Object Model (POM) is a design pattern which instruct us to,

  1. Treat each page in the our application as Java Objects.

  2. Treat each element in the screen like link,input box, check box, button etc., as the member variables of the object. (WebElement(s))

  3. All the action that we are going to perform on those elements are methods of that object.

By doing so we can achieve much cleaner, modular, reusable and robust framework.

For example take the Google's home page. In this scenario,

  1. The google home page becomes - GooglePage.java

  2. Search input becomes - private WebElement searchinput;

  3. Typing inside that text box will be like - public void searchText(String key) { searchinput.sendKeys(key + Keys.ENTER); }

public class GooglePage {
	
	@FindBy(name = "q")
	private WebElement searchinput;

	public void searchText(String key) {
		searchinput.sendKeys(key + Keys.ENTER);
	}
}

Selenium library has some inbuilt features which we can leverage to achieve POM. One such example is shown in above code @FindBy annotation.

PreviousTechnology StackNextSetup

Last updated 5 years ago

Was this helpful?