我正在为我的 testng-selenium-java 项目使用 ExtentReports 和 ItestListener,我的侦听器为 ExtentReports 的失败测试用例截屏,但问题是我的 testng.XML 中有多个类,我一口气运行它们,一个在另一个做不同的事情并拥有自己的司机之后。
在失败的情况下,Ilistener 的代码是 -
public void onTestFailure(ITestResult iTestResult)
{
System.out.println("I am in onTestFailure method " +
getTestMethodName(iTestResult) + " failed");
//Get driver from BaseTest and assign to local webdriver variable.
Object testClass = iTestResult.getInstance();
WebDriver webDriver = ((BaseTest) testClass).getDriver();
//Take base64Screenshot screenshot.
String base64Screenshot = "data:image/png;base64,"+((TakesScreenshot)webDriver).
getScreenshotAs(OutputType.BASE64);
//Extentreports log and screenshot operations for failed tests.
ExtentTestManager.getTest().log(LogStatus.FAIL,"Test Failed",
ExtentTestManager.getTest().addBase64ScreenShot(base64Screenshot));
}
如何确保在测试用例失败时采用失败测试用例类的驱动程序,因为在上面的代码中,始终只给出一个类的驱动程序,而不是当前类的驱动程序。