TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: Page Object Model vs Properties File: How to Choose
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Selenium Tutorial

Page Object Model vs Properties File: How to Choose

Last updated: Feb 25, 2024 10:35 am
By Meenakshi Agarwal
Share
7 Min Read
Page Object Model Vs Properties File in Selenium Webdriver
SHARE

This tutorial compares Page Object Model Vs Properties File approach. Page object model aka POM is a frequently used design pattern for automating the UI flows of a Web application. While using the properties file in Selenium Webdriver is a general concept. It stores large and complex locators by giving them user-friendly names. The only similarity between the duo is that both of them provide a way to form an object repository in Selenium Webdriver.

Contents
Properties File ApproachSingular Properties FileLocator Dependent Properties File.Meta Interfaces to Store LocatorsPage Object Model ApproachPros and Cons of POM

Page object model encapsulates the locators into classes and exposes methods to manage them. Whereas the properties file in Selenium Webdriver requires a custom Property class to provide a method to read locators. You can also achieve it by writing a Static method to access properties files and get locators. In this blog post, we’ll broadly discuss the differences between the Page Object Model and Properties File.

For readers who wish to learn Selenium from scratch, check out our step-by-step Selenium Webdriver Tutorial.

How to Choose Between Page Object Model & Properties File

  • Properties File Approach
    • Singular Properties File
    • Locator Dependent Properties File
    • Meta Interfaces to Store Locators
  • Page Object Model Approach
    • POM Sample
    • Pros and Cons of POM

Page Object Model Vs Properties File

Page Object Model Vs Properties File in Selenium Webdriver

There is no better way of learning than by using practical examples. Let’s begin with the properties file first so that you can easily understand the difference later. You’ll get to learn almost every little detail about the POM and Properties File.

Properties File Approach

There are many ways to structure and reference the Object Repositories (OR) using the properties file in Selenium Webdriver. We’ve also written a dedicated post on implementing property files, refer to it for more details.

Singular Properties File

In this method, you’ve to perform the following steps.

  • Store all the object locators in a single <UIMap.properties> file in the form of key-value pairs.
  • Create a <Properties.java> class that loads the locators at runtime.

Example

txtEmailId = //input[@id="email"]
btnRegister = //button[@class="register"]
...

Pros

  • Saves you from using long XPath and ID locators.
  • It’s easy to update the locator values.

Cons

  • The time to search a locator would increase in proportion to the size of the OR.
  • With time the size of the singular OR is going to grow. Managing a large repo would lead to performance issues.

Locator Dependent Properties File.

Classify the properties files based on the locator types in the following style.

  • Id.properties.
  • ClassName.properties.
  • XPath.properties and so on.

Examples

txtEmailId = //input[@id="email"]
btnRegister = //button[@class="register"]
...
lnkAccept=btn.green
lnkDeny=btn.red
lnkWait=btn.orange
...
btnDynamicRow=//table[@id="DynamicData"]/tbody/tr/td[3]
...

Pros

  • It’s easy to code when you want to –
    • Handle different types of locators based on their file names.
    • See how much each of the types is contributing to the size of the object repo.

Cons

  • Increases maintenance cost.
  • Lead to confusion when a single page consists of locators with different types.

Meta Interfaces to Store Locators

Use the following steps to apply this method.

  • Provide an interface for holding <By> locators.
  • Implement the interface by creating a Java class.
  • Create a class for every page of your web application.

Example

public class RegisterPage implements IRegisterPage {
...
}
 
public interface IRegisterPage {
    By idEmail = By.id("email")
    By idRegister = By.classname("btnRegister")
    ...
}

Pros

  • Since it’ll create context-based objects, so it would be easy to use them instead of directly dealing with the methods.
  • It solves most of the problems specified above.

Cons

  • Since it requires additional interfaces for each page class, so there could be a noticeable increase in the project footprint.

Page Object Model Approach

The page Object model works best when used in the right situation. It follows the lazy-initialization design. So the Webdriver doesn’t load the elements until they come in the picture. This model is a by-product of the Factory Design Pattern. It recommends creating separate Factory Objects to initialize the other objects. This method leaves behind all others in terms of both maintenance and performance.

Let’s see a quick example of using the page object model.

POM Sample

public class RegisterPage {
 
  @FindBy(id = "register")
  private WebElement registerButton;
 
  public RegisterPage(WebDriver driver) {
      PageFactory.initElements(driver, this);
  }
 
  public void clickRegisterButton() {
      registerButton.click();
  }
}
 
public class PageTest {

   @Test
   public void firstTest() {

      RegisterPage page = new RegisterPage(WebDriver driver);
      page.clickRegisterButton();
   }
}

Pros and Cons of POM

There are many benefits of the Page Object Model, some of them are as follows.

Pros

  • It enforces the creation of classes that are simple and follow user-friendly naming conventions.
  • You can rename the methods to make them relevant to the situation.
  • Since all the objects of a page stay in one class, so it’s easy to form a context between the page and locators.
  • The code is more maintainable and easy to debug.

Cons

  • Since the code in POM rests behind an abstraction layer, the testers may find it a bit difficult to grasp at the onset.
  • This model leads to loose coupling as it creates additional objects. And it could cause a slight drop in the performance at runtime.

Summary – Page Object Model Vs Properties File

However, the Page object model is the best & the easiest solution to implement. But it’s up to you and the circumstances which may make you choose a different approach.

That’s where the above post can guide you in making the decision to go either with the Page Object Model or the Properties File in Selenium Webdriver.

Finally, if you are happy with this post, please share it on social media. Also, care to like us on our social media accounts for access to our free resources.

Best,
TechBeamers

You Might Also Like

20 Demo Sites for Automation Testing

Page Object Model (POM) and Page Factory Guide in Selenium Java

Selenium 4 Relative Locators Guide

Selenium Version 4 Features – What’s New?

How to Inspect Element in Safari, Android, and iPhone

TAGGED:POM Design Pattern

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
Loading
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article How To Choose The Best Software Testing Service Provider Best Software Testing Service Providers
Next Article Selenium WebDriver TestNG Quiz for Testers Selenium WebDriver TestNG Quiz for 2024

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x