How to Create Object Repository in Selenium

On This Page What is an Object Repository in Selenium?June 18, 2026 · 6 min read · Tool Comparison

How to Create Object Repository in Selenium

Testing web application with frequently imply interacting with multiple web elements using locators. Hard-coding these locators direct in leads to code duplication and do maintenance difficult.

Overview

If a locator changes, updates must be made across multiple scripts, which is time-consuming. This is where an object repository helps.

An object secretary is a centralized storage location for web element locater, mapping unequalled component identifiers (keys) to their corresponding locators (values). It helps manage locators separately from test logic, improving tryout script maintainability.

Use Cases of Object Repository in Selenium

  • Store and manage locater for web elements in a fundamental location.
  • Reduce codification duplication by part locator from examination scripts.
  • Simplify updates when UI modification by updating locators in one spot.
  • Improve script maintainability, scalability, and readability.

This clause explores how to make and use an object repository in Selenium to streamline tryout automation and improve maintainability.

What is an Object Repository in Selenium?

An object repository is a centralized storage that holds web element locators as objects. In Selenium, QAs typically store these locators in a separate file telephone a properties file (.properties), which organizes datum in key-value duo. This properties file acts as the object repository for.

Depending on the automation model, object deposit can also be preserve using XML file or other formats.

The image below represents a sample Properties file. It has the extension make“ .properties ”

QAs can create two character of object repositories in Selenium WebDriver:

  1. Using a properties file in Selenium
  2. Using an XML file

Read More:

Types of Object Repository in Selenium

There are two common types of object repositories used in Selenium automation:

1. Properties File-Based Object Repository

  • Stores locators as key-value yoke in a.properties file.
  • Ideal for small to medium projects.
  • Easy to implement and maintain, but may not scale well for orotund test cortege.

2. Object Repository Using Page Object Model (POM)

  • Uses Java family to correspond web pages, storing locator as variables within page classes.
  • Offers better scalability and maintainability for big projects.
    Encourages detachment of page structure and test logic, following best practices in test automation design.

Early formats like XML or JSON can also be used for object repositories, depending on the undertaking ’ s necessity and framework.

For squad looking to enhance their summons, platforms like provide a reliable cloud infrastructure to run Selenium tests at scale. BrowserStack ’ s helps ensure your tests run consistently across different browsers and device, while your object repository sustenance your test scripts maintainable and scalable.

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

How to Create an Object Repository in Selenium

To make an object repository using a properties file in Selenium, follow these key measure:

1. Create a Properties file and add data

Please note: Here, it is acquire that the reader has basic knowledge on.

QAs first need to set up a introductory project structure on eclipse. To make a property file, one needs to follow the steps below:

  • Right-click onProject booklet & gt; New & gt; Early & gt; General & gt; File
  • Click Nextand so name the file (example: demo_repo.properties) and then click onFinish.

Now, one needs to store the data in this file in key-value pairs. Just double detent on your.properties fileand add the key-values.

This example uses the web elements of the Facebook login page. The XPath of the username, password, and login button will be added to the place file.

facebook.login.username.xpath=.// * [@ id='email '] facebook.login.password.xpath=.// * [@ id='pass '] facebook.login.Signup.xpath=.// * [@ id='loginbutton ']

The test example scenario includes three basic measure:

  1. Visiting Facebook login page
  2. Entering username & amp; password
  3. Clicking on login button

2. Reading data from the Properties file

To read data from the Properties file, you need to use the built-in Properties class that is available inJava.util.package.

So one needs to create an object of Properties stratum:

Properties obj = new Properties ();

Now you also need to make an object of FileInputStream class with its path pointing to the .properties file:

FileInputStream objfile = new FileInputStream (System.getProperty (`` user.dir '') + '' \\ & lt; name of the properties register & gt; '');

Now to integrate the properties file in your test book that includes locators, you need to load the file. To do this, you can use the load method of the holding class. Refer to the code snip below.

Properties obj = new Properties (); FileInputStream objfile = new FileInputStream (System.getProperty (`` user.dir '') + '' \\ & lt; name of the properties file & gt; ''); obj.load (objfile); String username = obj.getProperty (`` facebook.login.username.xpath '');

The string username will moderate the to find the username battlefield on the login page.

3. Using the Properties file in Selenium Script

Now to use the locator information available in the properties file, you require to pass the uncommitted datum as parameters using the.

driver.findElement (By.xpath (obj.getProperty (`` facebook.login.password.xpath ''))). sendKeys (`` adsadasdas '');

Refer to the complete code below for getting a sense of the program flow:

meaning java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; importee java.util.Properties; import org.openqa.selenium.By; signification org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class TestFacebook {@ Test world nothingness TestOR () throws IOException {// Specify the file location I used. operation hither because //we feature object repository inside project directory only File src=new File (`` .Object_Repo.properties ''); // Create FileInputStream object FileInputStream objfile=new FileInputStream (src); // Create Properties class target to say place register Properties obj=new Properties (); // Load file so we can use into our script obj.load (objfile); System.out.println (`` Property class load ''); // Open FirefoxBrowser WebDriver driver=new FirefoxDriver (); // Maximize window driver.manage () .window () .maximize (); // Pass application driver.get (`` http: //www.facebook.com ''); // getProperty Fetches the value of target key from the belongings file // In this suit entering username driver.findElement (By.xpath (obj.getProperty (`` facebook.login.username.xpath ''))). sendKeys (`` SeleniumWebDriver @ gmail.com ''); // getProperty Fetches the value of target key from the properties register // In this case entering watchword driver.findElement (By.xpath (obj.getProperty (`` facebook.login.password.xpath ''))). sendKeys (`` adsadasdas ''); // getProperty Fetches the value of target key from the properties file // In this suit clicking on login button driver.findElement (By.xpath (pro.getProperty (`` facebook.login.Signup.xpath ''))) .click ();}}

Using object repository in Selenium helps QAs manage their test suite more effectively. The centralized approach of maintaining the web element ’ s locator info make it easy for testing teams to make changes quickly, with less try. Thus, an understanding of Object Repository serves to make QA ’ s lives easier in a significant way.

Read More:

Advantages of Object Repository in Selenium

Using an object monument in Selenium offers several key benefits:

  • Centralized Locator Management:All element locators are stored in a single localisation, making it easier to deal and maintain tests.
  • Reduced Code Duplication:Locators are defined once and reused across multiple test scripts, ensuring clean and more organized codification.
  • Simplified Maintenance:If an component ’ s locator changes, it only needs to be updated in the object repository, saving time and exploit.
  • Improved Scalability:Helps scale exam automation projects by severalise test logic from UI constituent, endorse long-term task growth.
  • Enhanced Readability and Collaboration:Makes it leisurely for teams to read and qualify tests, as locator are managed in a integrated and consistent formatting.

By combining an object monument with a reliable testing infrastructure like BrowserStack, teams can ensure their Selenium tests remain maintainable and robust across browsers and devices.

Talk to an Expert

Conclusion

Using object deposit in Selenium helps QAs manage their more efficaciously. The centralized approach of maintaining the web element ’ s locator information make it leisurely for testing teams to make changes quickly, with less try. Thus, an understanding of Object Repository serves to make QA ’ s lives leisurely in a significant way.

Tags
64,000+ Views

# Ask-and-Contributeabout this matter with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free