i made a success selenium test case for login page, which a user enters a correct username and password and then hit login to forwarded to home page,issue is that when i change the password in the test class, the test always success i don't know why.
here's the test Class:
public class LoginTest extends TestCase {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:8080";
}
@Test
public void testLoginClass() throws Exception {
driver.get(baseUrl + "/MyAPP/login");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.id("j_username")).clear();
driver.findElement(By.id("j_username")).sendKeys("1");
driver.findElement(By.id("j_password")).clear();
driver.findElement(By.id("j_password")).sendKeys("wrong password");
driver.findElement(By.id("loginBtn")).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
@SuppressWarnings("unused")
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
please advise how to handle the fail of test case, let's suppose that after sometime the database is changed and there's no such user 1 which is success right now.