How and why create an object repository (for element locators) in a Selenium project?



  • 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!



  • The correct approach is to have the locators in each page object class as By variables or use page factory which declares the web elements and their locators together In my opinion, using object repositories in Selenium projects is a bad practice. The object repository concept comes from record-and-playback tools such as QTP. The object repository is a tree-like structure that is created while recording a test. It has attributes for each element of the page used in the test. Selenium does not have any record-and-play feature for test automation (Selenium IDE is not an automation tool). Using object repositories in Selenium projects (as property or csv or xml files) has many disadvantages such as since each locator is a line in a text file, it is impossible to open the declaration of the locator in the IDE (using F3 or Open Declaration) page object classes with no locator variables break the class encapsulation principle (methods of a class should execute on variables of a class) object repositories do not scale well for big pages; since big pages are bad and should be broken down in small pages, should we not have object repositories for each page widget? object repositories do not work with page factory Read more about the disadvantages on this medium.com article: https://medium.com/@alexsiminiuc3/dont-use-object-repositories-with-selenium-webdriver-ad14096528e5



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2