我犯了一个成功硒测试用例为登录页面,该用户输入正确的用户名和密码,然后点击登录转发到主页,问题是,当我在测试类更改密码,测试总是成功,我不知道为什么。如何在selenium测试用例中声明登录成功?
这里的测试类:
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;
}
}
}
请告知如何处理测试案例的失败,让我们假设一段时间之后,数据库中更改,有没有这样的用户1,它是成功的现在。
代码片断请这样断言? – 2012-01-17 15:47:20
我已经做了一个编辑,包括断言,它在红宝石 – Amey 2012-01-17 16:11:42
那么为你工作吗? – Amey 2012-01-17 19:49:54