TestNG對(duì)失敗時(shí)截圖處理
那如何把這個(gè)類(lèi)對(duì)象的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();
}
}
}
后再加上監(jiān)聽(tīng)即可:
@Listeners({ DotTestListener.class })
public class Test10 extends TestBase{
@Test
public void testInput(){
System.out.println(5/0);
}
}