Migration from Selenium RC to WebDriver

Selenium Remote control got birth from the JavaScriptTestRunner that Jason huggins developed for automating their In-House Time -n- Expenses application.

Selenium RC had few limitations that created serious problems with the advancement of rich internet applications like Same Origin Policy file Uploads and few others..

Selenium RC is officially deprecated now with no further development but with a maintenance mode and its high time that we need to migrate to WebDriver.

Over these past years, we have spent many time in developing automated web tests with selenium RC and its not possible to migrate Selenium RC Scripts to WebDriver overnight, but a high amount of time and cost involves in migrating scripts to WebDriver.

If you are starting fresh, then it should be WebDriver.

Using WebDriverBackedSelenium make’s sense to easily migrate your test scripts from Selenium Rc to WebDriver.

Let’s see how we migrate from Selenium RC to WebDriver

Selenium RC code look like this
[sourcecode language=”Java”]
String strBaseUrl = "http://assertselenium.com/";
String strBrowserName = "*firefox"
String strPortNumber = "5555"
String strHost = "localhost"

selenium = new DefaultSelenium(strHost, strPortNumber , strBrowserName , strBaseUrl);
selenium.click("link=Contact Me");

//Can be many more steps involved…


You may use any WebDriver implementation, here we use Firefox Driver

[sourcecode language=”Java”]
String strBaseUrl = "http://assertselenium.com";

//Creating a WebDriver implementation
WebDriver driver = new FirefoxDriver();

//Selenium rc implementation
Selenium selenium = new DefaultSelenium(driver, strBaseurl);

//Performing actions with selenium
selenium.click("link=Contact Me");

//Can be many more steps

[sourcecode language=”Java”]
/* And get the underlying WebDriver implementation back.
*This will refer to the same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver();

Using selenium.start() is not required because, we have already created the WebDriver session. At the end of the test we shall use the driver.quit() instead of selenium.stop().

WebDriver doesn’t support all browser’s as Selenium Rc used to support. In order to use that ability while still using the WebDriver you shall use the SeleneseCommandExecutor

It can be done using,
[sourcecode language=”Java”]
Capabilities dCaps = new DesiredCapabilities()
dCaps.setBrowserName("some new browser");
CommandExecutor executor = new SeleneseCommandExecutor("http:localhost:4444/", "http://www.google.com/", capabilities);
WebDriver driver = new RemoteWebDriver(executor, dCaps);

Hope that helps!!

Leave a Comment