top of page

How to implement an object repository in selenium with .properties file

Object repository is a file or a place where all the UI elements in the application can be mapped at one place at an application level instead of page level. There is no built in concept of repository in selenium but it can be implemented by using .properties file.

Advantages of using an object repository are:

1.Reduce code duplication

2.Value of any single locator changes to be updated throughout the project to ensure consistency.

3.Manage test suite more effectively

4.Test automation remains unaffected due to UI changes

I implemented this in one of the modules

1.First I created a file at application level.(It can also be created in the utils package)

2.I added all the key value pairs in the properties file for all the elements to be tested in different pages of the application. Here I have used only xpath, but an element can be identified by name, css ,etc.

Once the key and value is defined for an element in the properties file,the element can be called for any number of times for different test scenarios using the key.It need not be defined at page level unlike Page Factory

3. I created a file to parse the .properties file.I used By.xpath. Depending on the identifier used ,, By.cssselector etc can be used.

4.This is how the code was called using the key from .properties file in TestNG

Thus creating an object repository is an easier approach to maintain the code. Depending on the project circumstances either POM or Object Repository could be used.

143 views0 comments

Recent Posts

See All


Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page