Selenium Webdriver Object Repository and Object Recognition

In QTP, there is a concept called “Object Repository”. All the objects are added to Object Repository and the objects are used in the test. If there are any changes in the application then we need to update only Object Repository. But in selenium WebDriver, There is no any built-in facility to create object repository. So maintenance of page objects(Page element locators) becomes very hard If you will write all objects of page on code level.

Yes, we can use the below ways to create selenium WebDriver object repository:

Using properties file

A basic object repository can be implemented as a collection of key-value pairs, with the key being a logical name identifying the object and the value containing unique objects properties used to identify the object on a screen.

Static Variables

Instead of using locators directly in the tests we are going to use the locators in the form of static variables. Hence, there is no need to make any change to test cases, the only place where we need to make change is the “Class” containing static variable.

In QTP we can add object easily just using mouse, but in selenium WebDriver, it’s hard, yes, we can use the following ways to identify object:

  • Selenium IDE
  • FireFox – firebug, firepath
  • Chrome Developer Tool
  • IE Developer Tool

But it’s hard and time consuming, especially for newer in selenium automation, e.g., they need to know how to generate relative xpath although they don’t know what is xpath.

So now we have a solution, create a new little tool help us with object recognition, it’s very easy for any people, even they don’t know any relevant skills.

  1. Open the page you want to spy;
  2. Mouse over the element you want to spy;
  3. The relevant locator will display automatically;
  4. Right-click, copy any locator you need

Spy WebElement
Copy Locator

This is our first implementation, maybe in the following time, we can create a ‘real’ object repository(not belongs to the automation project):) we can add object just as QTP does, then we can use it generate selenium ‘Page Object’ script automatically. and maybe more and more…..

唐胡璐 wechat