如何在 Selenium Webdriver 中使用下面的 Assert 语句
- Assert.AssertTrue(条件,字符串)
- Assert.AssertFalse(Conditoin,String)
当条件失败时,请告诉我字符串语句的显示位置(在控制台/报告中)
最佳答案
public void doLogout() {
String curTitle=driver.getTitle();
jsExecution("rms.home.logout");
Assert.assertFalse(curTitle.equals(newTitle), "You've not been logged out");
}
public void stayTheSamePage(){
String curTitle = driver.getTitle();
String newTitle = driver.getTitle();
Assert.assertTrue(curTitle.equals(newTitle), "You've been redirected");
}
如果您想要检查某些内容并且您知道正确的行为(预期的行为)在条件下是错误的(例如您已登录并且页面标题不同),那么您使用 Assert.AssertFalse()
的基本想法.
如果预期行为在条件下为 True(例如页面标题相同),请使用 Assert.AssertTrue()
.
关于selenium - 需要一些示例如何在 selenium webdriver 中使用 TestNG 使用 Assertstatements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12351564/