Selenium – Creating Object Repository

by seetaram on June 1, 2011

Parameterization of a particular test is needed in order to avoid hard coding of values.  If a test is recorded with Selenium IDE, then all the values (e.g. locators) are hardcoded making it very difficult to execute with subsequent changes in the application.  In this post let us discuss a simple form of parameterization with creating a separate class for holding static variables for each locator.

The following example actually demonstrates the usage of parameterization.

Let us assume that our test suite contains more than 500 test cases and more than 50 different screens and we have thousands of objects on the application under test.  Multiple test cases may be (more than 10) using a particular screen (e.g. Contract creation screen).  If there is a change request from the client to enhance / change any of the object, then we need to update all the test cases.

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, there is no concept of Object Repository.  Using static variables we can create a similar kind of feature in order to handle frequent changes in the application under test (AUT).

We will have a look at the below code,

package com.selftechy.parameterization;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class AdvancedSearch extends SeleneseTestCase {
	private static SeleniumServer seleniumServer;
	public void setUp() throws Exception {
	selenium = new DefaultSelenium("localhost", 4444, "*chrome", "");
        seleniumServer = new SeleniumServer();

	public void testAdvancedSearch() throws Exception {"");"link=Advanced search");
		selenium.type(ORas.wedAllTheseWords, "selftechy, selenium, eclipse");, "label=20 results");;

	public void tearDown() throws Exception {

package com.selftechy.parameterization;

 * Author - Seetaram Hegde
 * This class holds all static values for objects of "Advanced Search"
 * page on Google Search
 * ORas - ObjectRepositoryAdvancedSearch
 * wed - Web Edit
 * wls - WebList - Dropdown
 * btn - Button
public class ORas {
	public static final String wedAllTheseWords="as_q";
	public static final String wedExactWord="as_epq";
	public static final String wlsReadingLevel="tbs";
	public static final String wlsResultsperPage="num";
	public static final String btnAdvancedSearch="//input[@value='Advanced Search']";

package com.selftechy.parameterization;

 * Author - Seetaram Hegde
 * This class holds all static values for objects of "Language Tools"
 * page on Google Search
 * ORlt - ObjectRepositoryLanguageTools

public class ORlt {
	public static final String wedSearchFor="clirq";
	public static final String wedTranslateText="source";
	public static final String btnTranslateandSearch="Translate and Search";


In this example, I created two different classes “ORas” and “ORlt” for two different screens.  Both of these classes hold objects in the form of 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.

{ 8 comments… read them below or add one }

vivek November 30, 2011 at 11:52 am

How can we use/link these ORas and ORlt with main test case?


seetaram December 1, 2011 at 3:04 am

With Selenium commands use ORas.wedAllTheseWords in the place of a locator

selenium.type(ORas.wedAllTheseWords, “selftechy, selenium, eclipse”);


Debasish Dutta January 11, 2012 at 8:04 am

Where to change value. if i want to put different value for search condition where i have to put. in the class or in the main class. please reply.


seetaram January 12, 2012 at 9:52 am

selenium.type(ORas.wedAllTheseWords, “selftechy, selenium, eclipse”); change “selftechy, selenium, eclipse” to “Test Automation with Selenium” (it should be done in the test method)


Hariharan M June 11, 2012 at 7:00 am

Hi seetharam,
Thanks for the valuable information. I was very much troubled with changes in object properties in web pages.


seetaram June 29, 2012 at 4:11 pm

keep the objects outside your script so that you can modify them whenever needed..


Ravi July 30, 2012 at 12:44 pm

Seetaram instead of putting as static variable, we can put all in file, Which will reduce the compile time. I mean to say no build is required, you can change properties values at any point of time.



seetaram August 13, 2012 at 2:29 pm

Yes..I tried to make things easier for the beginners!! Whatever you said is a good option.


Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email