Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some questions about creating an Object Repository for a selenium project:

1) What are the main reasons that we create an Object Repository, as opposed to hard coding the element IDs in our page classes?

2) What is the best approach to do this? I have seen people use an OR class with public static strings, and others create the OR class with private members with get/setters.

Your input is appreciated!

share|improve this question

I guess by object repository you mean external source (a file or DB) of locators for elements in your page objects.

I actually see no reason to follow this approach.

  1. Keeping locators in a separate repository is said to limit maintenance costs, as locators can be updated without a need of recompiling the code. However, both locators and page object codes are usually maintained by the same tester/team, so recompiling is not a big problem.
  2. Rather, I would say this approach increases the costs of maintenance, as locators are decoupled from elements definined in page objects. Hence, if you need to update locators you first need to understand which page object and which elements they refer to. On the other side, if you want to refactor your page object (e.g., rename one of its elements or move an element from one page object to another), you will need to take care for corresponding locators in your object repository, loosing all support your IDE would give you, if both locators and elements where parts of page object classes.

Instead, I would go for a solution with @FindBy annotations, e.g.,

@FindBy(id = "password")
WebElement passwordField;

This gives you a nice balance of separating elements location from operations performed on those elements, like clicking, while still keeping locators close to the elements they identify.

share|improve this answer

Will suggest the approach to use XML based object repository which is also tool agnostic. Pls refer the link for implementation details:

share|improve this answer
Linked sites disappear sometimes without trace. Please try to include the most important parts inline into your answers and link only additional information. – Edu Nov 17 '14 at 8:30
Sure Edu.Here is the link to the implementation of xml based repository in… – Vishal Aggarwal Nov 17 '14 at 10:00

I am not sure what is your definition of "Object Repository". I am going to assume it is some kind of central place for locators of page elements (by id, name, link text, css, or even xpath). If i am wrong, we can just kill the answer.

In few places I've seen suggesting one central file for all locators, but it can grow pretty big pretty fast. I am using pageObject design pattern, and locators seems to belong to the page, so I keep them there. I am also using Python so I mostly keep it simple.

share|improve this answer
Thanks, I guess one benefit of keeping them in a centralized place is when you use some elements across multiple pages and multiple tests, in this situation, how would you handle? – user2917239 Jun 4 '14 at 21:34
@user2917239, through PageObject class inheritance. I.e, you could create an abstract class that contains locators/elements used across multiple pages and then multiple PageObject classes that inherit from it. – dzieciou Jun 5 '14 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.