Convert Selenium projects from RC (selenium 1.0) to Web Driver (selenium 2.0)

Why convert Selenium projects from RC to Web Driver?

A few reasons are that 

1. Web Driver has almost all development support now and RC is slowly being "retired"

2. Web Driver interacts natively with the browsers and not through a proxy like RC; 
             More details on how RC simulates the interaction with the browser

3. Web Driver allows writing object oriented code

4. No server needs to be started for Web Driver

5. The scripts performance is much better when using the html, in memory driver
           More details on the RC - Web Driver differences



The first thing to do when converting the RC project to Web Driver is code re-factoring, making the code as simple and as efficient as possible:

1. All code repetitions should be removed

2. Page object classes should be created

          More details on page object classes:

                       Selenium Basics - why is page object needed?

                       Selenium RC - code refactoring and page object model

3. All code that interacts with the page (through Selenium commands) should be removed from the test methods and placed in the page object classes



After refactoring the project, the number of lines that include Selenium commands will be reduced considerably. 

The remaining lines that include Selenium commands will need to be modified for the Web Driver API.

No changes should be needed for the test methods.





The Web Driver API is as clear as the RC API.

See below RC and Web Driver code that do the same thing:


Select a value in a list

RC
selenium.select(listPath, listItem);
assertTrue(selenium.getSelectedLabel(listPath).equalsIgnoreCase(listItem) == true);

Web Driver
Select ddown = new Select(driver.findElement(By.xpath(listPath)));
dd.selectByVisibleText(listItem);
assertTrue(dd.getFirstSelectedOption().getText().equalsIgnoreCase(listItem) == true);



Type a value in a textbox

RC
selenium.type(textboxPath, textboxValue);
assertTrue(selenium.getValue(textboxPath).equalsIgnoreCase(textboxValue) == true);

Web Driver
WebElement element = driver.findElement(By.xpath(textboxPath));
element.sendKeys(textboxValue);         
assertTrue(element.getAttribute("value").equalsIgnoreCase(textboxValue) == true);
             


Check a checkbox

RC
selenium.check(checkbox);
assertTrue(selenium.isChecked(checkbox) == true);

Web Driver
WebElement checkbox = driver.findElement(By.xpath(checkboxPath));
checkbox.click();
assertTrue(checkbox.isSelected() == true);
   


Click a link or a button

RC
selenium.click(includeAddSectionLinkXPATH);

Web Driver
driver.findElement(By.xpath(includeAddSectionLinkXPATH)).click();
               


Check if an element is visible

RC
return selenium.isVisible(elementPath);

Web Driver
assertTrue(driver.findElement(By.xpath(elementPath)).isDisplayed() == true);



Get the length of an HTML element value

RC
return (selenium.getText(elementPath).length() > 0);

Web Driver
Integer fieldLength = driver.findElement(By.xpath(elementPath)).getText().length();





Share this