Tuesday, May 15, 2012

Introduction to Web Driver 2.0 with a simple example

A simple way to begin web driver 2.0. Install Selenium IDE in your firefox browser and create the script by record and playback method. For instance, try google or irctc site.


Convert your code into Webdriver by Export test case option available in IDE.


A sample script is given below,



public class google {
private WebDriver driver;


@Before
public void setUp() throws Exception {
driver = new FirefoxDriver(); //Initializing firefox driver
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
}


@Test
public void test() throws Exception {
driver.get("http://www.google.co.in/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Testing");
driver.findElement(By.id("gbqfq")).sendKeys(Keys.ENTER); //Hitting Enter for search
driver.findElement(By.linkText("Software testing - Wikipedia, the free encyclopedia")).click();
}


@After
public void tearDown() throws Exception {
driver.quit();

}

}



1 comment:

  1. Here am unable to find the id gbqfq. Instead of that I can able to find gbqfqw, gbqfw.

    ReplyDelete