Page Object Model Vs Properties File in Selenium Webdriver

Page object model also known as 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.

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.

1- Implementing Properties File in Selenium Webdriver.

There are many ways to structure and reference the Object Repositories (OR) using the properties file in Selenium Webdriver.

1.1- Singular Properties File.

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

1.1.1- Store all the object locators in a single <UIMap.properties> file in the form of key-value pairs.

1.1.2- Create a <Properties.java> class which loads the locators at runtime.

Example.

Pros.

1- Saves you from using long XPath and ID locators.

2- It’s easy to update the locator values.

Cons.

1- Time to search a locator would increase in proportion to the size of the OR.

2- With time the size of the singular OR is going to grow. Managing a large repo would lead to performance issues.

1.2- Locator Dependent Properties File.

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

1.2.1- Id.properties.

1.2.2- ClassName.properties.

1.2.3- XPath.properties and so on.

Examples.

Pros.

1- It’s easy to code for handling different types of locators based on their file names.

2- It’s easy to see how much each of the types is contributing to the size of the object repo.

Cons.

1- Increases maintenance cost.

2- Lead to confusion when a single page consists of locators with different types.

1.3- Meta Interfaces to Store Locators.

Use the following steps to apply this method.

1.3.1- Create an interface holding <By> locators.

1.3.2- Implement the interface by creating a Java class.

1.3.3- Create a class for every page of your web application.

Example.

Pros.

1- It’ll create context-based objects. So, it’s much easier to handle the object than the earlier methods.

2- It solves most of the problems specified above.

Cons.

1- It’ll require additional interfaces for each page class. It would lead to a noticeable increase in the project footprint if not significant.

 

2- Using Page Object Model in Selenium Webdriver.

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.

Example.

 

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

Pros.

1- Provides classes which are simple and follows a user-friendly naming convention.

2- Allows renaming the method to make it relevant to the situation.

3- Keeps all the objects of a page in one class. So, it’s easy to form a context between the page and locators.

4- Readability is high. Maintainability is low. And debugging is easy.

Cons.

1- Supporting loose coupling by creating additional objects brings down the performance.

2- Makes code a little difficult to read as all of it is behind an abstraction layer.

 

The Conclusion – Page Object Model Vs Properties File.

Though 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. Hopefully, you would now be able to sketch a clear difference between the Page Object Model and the Properties File in Selenium Webdriver.

If you liked this post, then do share this post on social media. Also, like us on facebook, follow on Twitter and G+.

 

Learn, Grow & Succeed,

TechBeamers.

Leave a Reply


*