selenium - 需要一些示例如何在 selenium webdriver 中使用 TestNG 使用 Assertstatements

标签 selenium testng

如何在 Selenium Webdriver 中使用下面的 Assert 语句

  1. Assert.AssertTrue(条件,字符串)
  2. 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/

相关文章:

testing - Geb 设置值以选择问题

c# - 将浏览器缩放设置为 80% 的 ChromeOptions

selenium - 尝试通过geb启动Internet Explorer时,将打开firefox

python - 抓取的网站数据未写入 CSV

java - 程序启动 testNG selenium 测试卡住

java - 动态方法调度

firefox - 60 秒内无法获得稳定的 Firefox 连接 (127.0.0.1 :7055) ubuntu

java - 无法读取单元测试成功率,可以读取jacoco生成的单元测试覆盖率

java - 放置在单独的测试类中时代码不执行

maven - 如何通过从 Web 界面单击来触发 Junit/Testng 测试运行