Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. public void testUserCanLogInAndLogOutAgain() {
  2.     WebDriver driver = new HtmlUnitDriver();
  3.     driver.get("http://localhost:8080/yourapp");
  4.     WebElement login = driver.findElement(By.id("login.link"));
  5.     login.click();
  6.    
  7.     WebElement usernameField = driver.findElement(By.id("login.username"));
  8.     usernameField.sendKeys("username");
  9.  
  10.     WebElement passwdField = driver.findElement(By.id("login.password"));
  11.     passwdField.sendKeys("password");
  12.  
  13.     WebElement loginButton = driver.findElement(By.id("login.submit"));
  14.     loginButton.submit();
  15.  
  16.     // ensure that the user's log in was successful
  17.     // throws a NoSuchElementException if the text isn't found
  18.     driver.findElement(By.xpath("//p[contains(text(), 'Welcome, username!')]"));
  19.  
  20.     WebElement logout = driver.findElement(By.id("logout.link"));
  21.     logout.click();
  22.  
  23.     // ensure that the user's log out was successful
  24.     driver.findElement(By.xpath("//p[contains(text(), 'Please log in')]"));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement