Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

3 Answers 3

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

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 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 at 12:01

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 at 8:30
    
Sure Edu.Here is the link to the implementation of xml based repository in SO.stackoverflow.com/questions/26758299/… –  Vishal Aggarwal Nov 17 at 10:00

Your Answer

 
discard

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.