Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created May 6, 2026 17:09
Show Gist options
  • Select an option

  • Save borodicht/3887bf0630f8e4c3683702ff600a533a to your computer and use it in GitHub Desktop.

Select an option

Save borodicht/3887bf0630f8e4c3683702ff600a533a to your computer and use it in GitHub Desktop.
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest {
@Test
public void checkLoginWithPositiveCred() {
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.className("submit-button")).click();
String title = driver.findElement(By.cssSelector("[data-test = title]")).getText();
Assert.assertEquals(title, "Products");
}
@Test
public void chekLoginWithEmptyUserName() {
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).sendKeys("");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.className("submit-button")).click();
String error = driver.findElement(By.cssSelector("[data-test = error]")).getText();
Assert.assertEquals(error, "Epic sadface: Username is required");
}
@Test
public void chekLoginWithEmptyPassword() {
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("");
driver.findElement(By.className("submit-button")).click();
String error = driver.findElement(By.cssSelector("[data-test = error]")).getText();
Assert.assertEquals(error, "Epic sadface: Password is required");
}
@Test
public void chekLoginWithNegativeCred() {
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("user-name")).sendKeys("test");
driver.findElement(By.name("password")).sendKeys("secret_sauce");
driver.findElement(By.className("submit-button")).click();
String error = driver.findElement(By.cssSelector("[data-test = error]")).getText();
Assert.assertEquals(error, "Epic sadface: Username and password do not match any user in this service");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment