TestNG对失败时截图处理
那如何把这个类对象的driver属性给传到onTestFailure方法里去?
public class DotTestListener extends TestListenerAdapter {
@Override
public void onTestFailure(ITestResult tr) {
try {
TestBase tb = (TestBase) tr.getInstance();
WebDriver driver = tb.getDriver();
System.out.println(driver.getTitle());
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
后再加上监听即可:
@Listeners({ DotTestListener.class })
public class Test10 extends TestBase{
@Test
public void testInput(){
System.out.println(5/0);
}
}