Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void testUserCanLogInAndLogOutAgain() {
- WebDriver driver = new HtmlUnitDriver();
- driver.get("http://localhost:8080/yourapp");
- WebElement login = driver.findElement(By.id("login.link"));
- login.click();
- WebElement usernameField = driver.findElement(By.id("login.username"));
- usernameField.sendKeys("username");
- WebElement passwdField = driver.findElement(By.id("login.password"));
- passwdField.sendKeys("password");
- WebElement loginButton = driver.findElement(By.id("login.submit"));
- loginButton.submit();
- // ensure that the user's log in was successful
- // throws a NoSuchElementException if the text isn't found
- driver.findElement(By.xpath("//p[contains(text(), 'Welcome, username!')]"));
- WebElement logout = driver.findElement(By.id("logout.link"));
- logout.click();
- // ensure that the user's log out was successful
- driver.findElement(By.xpath("//p[contains(text(), 'Please log in')]"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement