Skip to content

Instantly share code, notes, and snippets.

@rajaraodv
Created August 18, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajaraodv/303a7be28dcf8ceeb41c104e8a94c659 to your computer and use it in GitHub Desktop.
Save rajaraodv/303a7be28dcf8ceeb41c104e8a94c659 to your computer and use it in GitHub Desktop.
@Test
public void loginTest() {
//Open browser
driver.get("https://demo.applitools.com/loginBefore.html");
//Click on the Login button
driver.findElement(By.id("log-in")).click();
//Assert the error text
assertEquals("Please enter username and password",
driver.findElement(By.id("alert")).getText());
//Assert if username field exists
assertTrue((driver.findElement(By.id("username")) instanceof WebElement));
//Assert username placeholder text
assertEquals("Enter your username",
driver.findElement(By.id("username")).getAttribute("placeholder"));
//Assert username label exists
assertEquals("Username", driver.findElement(By.xpath("(//label)[1]")).getText());
//Assert if password field exists
assertTrue((driver.findElement(By.id("password")) instanceof WebElement));
//Assert password placeholder text
assertEquals("Enter your password",
driver.findElement(By.id("password")).getAttribute("placeholder"));
//Assert password label exists
assertEquals("Password", driver.findElement(By.xpath("(//label)[2]")).getText());
//Assert if SignIn button field exists
assertTrue((driver.findElement(By.id("log-in")) instanceof WebElement));
//Assert if SignIn buttons label is "Sign In"
assertEquals("Sign in", driver.findElement(By.id("log-in")).getText());
//Assert Remember Me checkbox exists
assertTrue((driver.findElement(By.xpath("//input[@class='form-check-input']")) instanceof
WebElement));
//Assert if Remember Me text exists
assertEquals("Remember Me", driver.findElement(By.xpath("(//label)[3]")).getText());
//Assert if Twitter button exists
assertTrue(driver.findElement(By.xpath("//form//a[1]//img[1]")) instanceof WebElement);
//Assert if Facebook button exists
assertTrue(driver.findElement(By.xpath("//a[2]//img[1]")) instanceof WebElement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment