Using Selenium 2 Webdriver to test HTML5 – Drag and Drop example

Here is a sample test code that I have written in Selenium 2 Webdriver coded in Java that explains you how Webdriver can be used for testing HTML5 pages.
I am testing a simple HTML5 page – http://jqueryui.com/draggable/

import java.util.NoSuchElementException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class HTML5Test {
//WebDriver driver = new InternetExplorerDriver();
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception {
driver.get("http://jqueryui.com/draggable/");
}

@Test
public void HTML5() throws Exception {
driver.switchTo().frame(driver.findElement(By.className("demo-frame")));
Thread.sleep(3000);
if(!isElementPresent(By.xpath("//div[@id='draggable']")))
{
Thread.sleep(3000);
}
WebElement draggable = driver.findElement(By.xpath("//div[@id='draggable']"));
new Actions(driver).dragAndDropBy(draggable, 200, 10).build().perform();
Thread.sleep(10000);
}

@After
public void tearDown() throws Exception {
driver.quit();
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}

If you have any questions regarding testing HTML5 pages using Selenium 2 Webdriver please feel free to post them.

Selenium IDE 1.5.0 to be released on 15th December 2011

Selenium IDE 1.5.0
New – Added support for Firefox 9
Bug – Changes to user extensions weren’t being updated in Firefox 8 – issue 2801
Bug – Security error was thrown when trying to type into file (upload) input fields in Firefox 8 – issue 2826
Bug – Improved French locale – issue 1912
Bug – break command was failing – issue 725
Bug – source view is now fixed width (monospace) – issue 522
New – Implemented ‘select’ formatting for WebDriver bindings (Java, C#, Python, Ruby)
Bug – Fixed compile-time and run-time errors in the code formatted for WebDriverBackedSelenium
Bug – Fixed ‘baseUrl’ and ‘get’ formatting errors in various formatters to handle relative and absolute URLs

Selenium the Agile automation testing tool

Test automation is usually lagging behind development of new functionality. The tools that are used to automate are dependent on the UI and this causes automation of the functionality to start only after the environment and the UI are stable.

Selenium is the test automation tool that helps test below the UI layer. The automation can be done earlier even before the UI is completely ready or matured.

Selenium is language independent and this makes to unique as testers/ developers can start coding as they code the application. You can code the Selenium automation scripts in PHP, Java, C#, Ruby, Python. Selenium uses locator – an element locator on a webpage to identify the element on the webpage.

Ideally its good to code the test scripts in the language the web application is built; by doing so you can integrate the test scripts in your nightly build and help speed up the QA process.

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.