Object Repository Concept In Selenium

Share and Enjoy !

Object repository is place where we store all information related to an object. Typically in Quick Test Professional it is an optional part.[Descriptive programming]. But we use it regularly. We depend on QTP to identify object during run time and play back time.
The below written posts you help you to get more details about the same:

But when it comes to selenium there are way to store Object’s properties.
In selenium we generally store the xpath or relative paths or locator information.


The ways you can store these are..

  • Excel–Here you need POI jar to read and write
  • Notepad/CSV–File operation in java
  • XML–File operation
  • Class page wise
  • Using Inner class[Nested class concept]
Excel will typically Look like-

!Yahoo Home Page

 XML format
!Yahoo Home Page
<Object name> usrname_txt <Property type> xpath < Property  Value>//*[@id=’username’]
<Object name> findppl_txt <Property type> classname < Property  value> searchIconBorder

Notepad format–

Class Page Wise
Class LoginPage{
     String userName=By.xpath(//*[@id=’username’])
     String password=by.xpath(//*[@id=’passwd’])
But these are ok when you are a learner or your test is significantly low in size or time. These methods are not effective when your test is very big in nature or say test will be running for 3 days or 4 days.Also they need either a 3rd party jar like-POI or java’s file handling operation which are not great for architecture point of view when time is a constraint.

So What could be the solution..
I would prefer the inbuilt nested class structure approach should be taken when your test is really big.

let me explain how..

public static class LoginPage{
private static class Login{
String userName=By.xpath(//*[@id='username'])
String password=by.xpath(//*[@id='passwd'])
private static class bodyElement{


See also  Shall We Execute Our Automation Test case in Random Order??

Well the advantages for this approach are–

  • Since they are static they will be loaded when you are trying to run login class. 
  • All objects will be available in Primary memory so no delay in execution of the test.
  • Readability will be easy but your test will remain huge
  • Less dependency on the external jars so delay in getting the data.
  • your primary memory will be free from the unwanted code.
  • Let JVM decide which objects and data will present on the memory  instead of us!!!
  • Garbage collection will be effectively fast.[Note we do not have any control on that programming] so helping GC by reducing load will be good from architecture point of view.

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *