Thursday, December 16, 2010

WebDriver

WebDriver
Uses Selenium’s javascript Selenium-Core. WebDriver does not depend on a javascript core embedded within the browser, therefore it is able to avoid some long-running Selenium limitations.
Sample:
package
com.sample.tests;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.RenderedWebElement;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LoginPage {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
WebDriver driver = new FirefoxDriver();

// Open Loginpage
driver.get("http://localhost:8220/login.jsp");

// Enter the query string "Cheese"
WebElement userId = driver.findElement(By.id("loginName"));
WebElement password = driver.findElement(By.id("password"));
WebElement submit = driver.findElement(By.id("submitbtn"));

loginName.sendKeys("Maddy");
password.sendKeys("pass");
submit.click();
try{
if(driver.findElement(By.id("LoggedusrNm"))!=null)
Assert.assertEquals("Done");
}catch(NoSuchElementException e){
Assert.fail("No LoggedUser label available");
}
}
}

1 comment:

Anonymous said...

Simple example. Nice.