Object Repository Properties File

The Object Repository Properties File is a standard properties file used to store object locators in a structured and maintainable format. It follows the key=value format, where:

  • The key uses dot notation for organization.
  • The value follows the format: locatorType:data, where locatorType is any supported Selenium locator (e.g., id, name, xpath, cssSelector).

Recommended Best Practices

  • Use XPath for Consistency – We recommend using XPath as the primary locator format for improved flexibility and robustness.
  • Maintain Readability – Follow a structured naming convention to keep locators easy to understand and manage.

Placeholder Support

Placeholders are allowed in the locator values using curly braces {}, followed by a number (starting at 0).

  • {0} will be replaced with the first value provided in the Object Option field of the test case file.
  • Additional placeholders {1}, {2}, etc. can be used for dynamic locators requiring multiple replacements.

Example Format

properties
myproject.login.username_field=xpath://input[@id='user_{0}']
myproject.login.password_field=xpath://input[@id='pass_{0}']
myproject.mainmenu.settings_button=xpath://button[text()='{0}']

In a test case, if the Object Option provided is admin, then:

plaintext
myproject.login.username_field → //input[@id='user_admin']

Why Use an Object Repository?

  • Centralized Object Management – Keeps test cases clean by separating locators from automation logic.
  • Easier Updates – If an element locator changes, it only needs to be updated in one place.
  • Supports Dynamic Locators – Allows flexible test execution with runtime-generated values.

By following this structured approach, the Object Repository Properties File enhances maintainability, reusability, and efficiency in test automation.

# Objects file
# Contains all the objects for the website
#
# Project Name: swaglabs
#
# object values
# project.page.object=xpath:...
swaglabs.login.username=xpath://input[@id='user-name']
swaglabs.login.userpassword=xpath://input[@id='password']
swaglabs.login.loginbutton=xpath://input[@id='login-button']
swaglabs.login.errormessage=xpath://h3[@data-test='error']
# page header
swaglabs.header.menu-xpath://button[@id='react-burger-menu-btn']
swaglabs.header.cart=xpath://a[@class='shopping_cart_link']
swaglabs.header.cartbadge=xpath://span[@class='shopping_cart_badge']
# Banner section
swaglabs.banner.name=xpath://span[@class='title']
swaglabs.banner.backtoproducts=xpath://button[@id='back-to-products']
swaglabs.banner.sort=xpath://select[@class='product_sort_container']
# Menu items
swaglabs.bannermenuitems.allitems=xpath://select[@class='product_sort_container']
swaglabs.bannermenuitems.about=xpath://a[@id='about_sidebar_link']
swaglabs.bannermenuitems.logout=xpath://a[@id='about_sidebar_link']
swaglabs.bannermenuitems.reset=xpath://a[@id='reset_sidebar_link']
swaglabs.bannermenuitems.close=xpath://button[@id='react-burger-cross-btn']
# Products page
swaglabs.products.productsheader=xpath://div[@class='header_secondary_container']/span
swaglabs.products.filtersort=xpath:select[@class='product_sort_container']
# Products
# //div[@class='inventory_item'][1]
# Inventory Items by ID
swaglabs.productsbyid.image=xpath://div[@class='inventory_item'][{0}]/div/a/img
swaglabs.productsbyid.itemname=xpath://div[@class='inventory_item'][{0}]/div/div[@class='inventory_item_label']/a
swaglabs.productsbyid.itemdescrip[tion=xpath://div[@class='inventory_item'][{0}]/div/div[@class='inventory_item_label']/div
swaglabs.productsbyid.itemprice=xpath://div[@class='inventory_item'][{0}]/div/div[@class='pricebar']/div[@class='inventory_item_price']
swaglabs.productsbyid.addtocart=xpath://div[@class='inventory_item'][{0}]/div/div[@class='pricebar']/button