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
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. 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 This clause explores how to make and use an object repository in Selenium to streamline tryout automation and improve maintainability. 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: Read More: There are two common types of object repositories used in Selenium automation: 1. Properties File-Based Object Repository 2. Object Repository Using Page Object Model (POM) 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. To make an object repository using a properties file in Selenium, follow these key measure: 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: 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. The test example scenario includes three basic measure: 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: Now you also need to make an object of FileInputStream class with its path pointing to the .properties file: 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. The string username will moderate the to find the username battlefield on the login page. Now to use the locator information available in the properties file, you require to pass the uncommitted datum as parameters using the. Refer to the complete code below for getting a sense of the program flow: 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: Using an object monument in Selenium offers several key benefits: 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. 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. # Ask-and-Contributeabout this matter with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.How to Create Object Repository in Selenium
Overview
What is an Object Repository in Selenium?
Types of Object Repository in Selenium
Encourages detachment of page structure and test logic, following best practices in test automation design.How to Create an Object Repository in Selenium
1. Create a Properties file and add data
facebook.login.username.xpath=.// * [@ id='email '] facebook.login.password.xpath=.// * [@ id='pass '] facebook.login.Signup.xpath=.// * [@ id='loginbutton ']
2. Reading data from the Properties file
Properties obj = new Properties ();
FileInputStream objfile = new FileInputStream (System.getProperty (`` user.dir '') + '' \\ & lt; name of the properties register & gt; '');
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 '');
3. Using the Properties file in Selenium Script
driver.findElement (By.xpath (obj.getProperty (`` facebook.login.password.xpath ''))). sendKeys (`` adsadasdas '');
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 ();}}Advantages of Object Repository in Selenium
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously