在我的 webdriver 脚本中,我有三种方法
setup, test and tearDown
遵循junit约定。
在test
方法中,我很少有这样的断言
@Test
public void testStudentHome() throws Exception {
String classCode = "I6OWW";
Utilities.studentSignin(driver, baseUrl);
assertEquals(true, sth.openNotification());
assertEquals("My Scores", sth.myScores(true));
}
这sth
是我在其上执行测试并且在setup
方法中创建的 PageObject。
我从这样的main
方法中调用所有这三种方法:
public static void main(String[] args) {
StudentHomeTest sht = new StudentHomeTest();
try {
sht.setup();
sht.testStudentHome();
sht.tearDown();
} catch (Exception ex) {
Logger.getLogger(StudentHomeTest.class.getName()).log(Level.SEVERE, null, ex);
sht.tearDown();
}
}
现在,如果某个断言失败,则在运行测试时,测试方法应该(这是我所期望的)抛出异常并且该main
方法应该调用该tearDown
方法。但这不会发生。并且浏览器窗口继续停留在那里。我正在使用 netbeans ide 来运行测试。