5.1. Form Authentication
Last updated
Was this helpful?
Last updated
Was this helpful?
<form name="login" id="login" action="/authenticate" method="post" >
<div class="row">
<div class="large-6 small-12 columns">
<label for="username">Username</label>
<input type="text" name="username" id="username"/>
</div>
</div>
<div class="row">
<div class="large-6 small-12 columns">
<label for="password">Password</label>
<input type="password" name="password" id="password"/>
</div>
</div>
<button class="radius" type="submit">
<i class="fa fa-2x fa-sign-in">
Login
</i>
</button>
</form>
Brainstorm questions
What is tag name?
What are attributes which has specified meaningful value?
What is tex?
public class FormAuthenticationTest {
WebDriver driver;
@BeforeClass
void setup() {
driver = new ChromeDriver();
}
@BeforeMethod
void load() {
driver.get("https://the-internet.herokuapp.com/login");
}
@Test
void validCredential() {
driver.findElement(By.id("username")).sendKeys("tomsmith");
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!");
driver.findElement(By.xpath("//*[@type='submit']")).click();
Assert.assertEquals(driver.getCurrentUrl(), "https://the-internet.herokuapp.com/secure");
Assert.assertTrue(driver.findElement(By.id("flash-messages")).isDisplayed()); //You logged into a secure area!
}
@Test
void invalidCredential() {
driver.findElement(By.id("username")).sendKeys("tomsmith");
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword");
driver.findElement(By.xpath("//*[@type='submit']")).click();
Assert.assertEquals(driver.getCurrentUrl(), "https://the-internet.herokuapp.com/login");
Assert.assertTrue(driver.findElement(By.className("error")).isDisplayed());
}
@AfterClass
void tearDown() {
driver.quit();
}
}