Search This Blog

Friday, July 22, 2011

Easy Way To Automate Using WebDriver

WebDriver is a clean, fast framework for Automation development of web-apps. WebDriver takes many advantages over selenium because selenium is written in java-script which causes a significant weakness: browsers impose a pretty strictly model , try to upload a file ,form control etc.
webDriver takes a different approach to solve the same problem as selenium. Rather than being running a java-script application within a browser, it uses whichever the mechanism is most appropriate to control the browser. Like for Firefox ,this means that webDriver is implemented as an extension.
The real beauty which I like most is real time environment, which means we are more closely modeling how the user interacts with the browser, and that we can type into "file" input elements. WebDriver can make use of facilities offered by the Operating System.
With the benefit of hindsight, we have developed a cleaner, Object-based API for WebDriver, rather than follow Selenium's dictionary-based approach.

Please download the respective jar related to your language from google code selenium project Download

Now follow below steps:-
1:- Extract the download file into a folder name and include the jars file ion your ClassPath
2:- Sample coding in java

import junit.framework.TestCase;
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; public class WebDriverTest extends TestCase{
public void test_hellotest()throws Exception{
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
// Find the text input element by its name WebElement element = driver.findElement("q"));
// Enter something to search for
element.sendKeys("Niraj Kumar");
// Now submit the form. WebDriver will find the form for us from the element
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());