Page Object Model Or Properties File – Which One Should You Use?

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 object repository in Selenium Webdriver.

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. Or you can also achieve it by writing a Static method to access properties file and get locators. In this blog post, we’ll broadly discuss the differences between the Page Object Model and Properties File in Selenium Webdriver.

Table of Content.

Page Object Model Vs Properties File in Selenium Webdriver.

Page Object Model Vs Properties File in Selenium Webdriver

There is no better way of learning than by using the 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 file, refer 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 which loads the locators at runtime.

Example.

Pros.

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

Cons.

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

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.

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.

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 picture. This model is a by-product of the Factory Design Pattern. It recommends creating separate Factory Object 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 page object model.

POM Sample.

Pros and Cons of POM.

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

Pros.

  • It enforces to create classes which 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, so 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.

And 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 liked this post, then please share it on social media. Also, do like us on Facebook and follow on Twitter and G+.

Learn, Grow & Succeed,

TechBeamers.

5 Comments

  1. Jeegar Dalal Reply
  2. kunal Reply
    • Meenakshi Agarwal Reply
  3. balaji Reply
    • Meenakshi Agarwal Reply

Leave a Reply

*