1
I created a report template for my test project that is up to now meeting my demand, however, if the test fails outside the@Test tag the report is not generated (being some connection error, or driver error, etc). I believe this is because the test does not pass the @Aftermethod and @Aftertest tags when errors like this happen, and therefore I cannot run the commands extent.flush() and extent.close() and the html file is not created. Any suggestions what I can do? Follow code in Java below:
@BeforeTest
public void startTest() {
className = this.getClass().getName();
String dateName = new SimpleDateFormat("dd-MM-yyyy hhmmss").format(new Date());
String userDir = System.getProperty("user.dir");
nomePasta = className.replace("MOBILEX_AUTOMACAO.TEST.", "") + " " + dateName;
new File(userDir + "\\target\\reports\\" + nomePasta);
extent = new ExtentReports(userDir + "\\target\\reports\\" + nomePasta + "\\"
+ className.replace("MOBILEX_AUTOMACAO.TEST.", "") + "REPORT.html", true);
extent.addSystemInfo("Nome APP", "MobileX");
extent.loadConfig(new File(userDir + "\\extent-config.xml"));
}
@AfterMethod
public void getResult(ITestResult result) throws Exception {
if (result.getStatus() == ITestResult.FAILURE) {
String screenshotPath = getScreenhot(result.getName());
logger.log(LogStatus.FAIL, "Test Case Failed is " + result.getThrowable());
logger.log(LogStatus.FAIL, "Test Case Failed is " + result.getName());
logger.log(LogStatus.FAIL, logger.addScreenCapture(screenshotPath));
} else if (result.getStatus() == ITestResult.SUCCESS) {
logger.log(LogStatus.PASS, "Test Case passed is " + result.getName());
}
extent.endTest(logger);
DriverFactory.killDriver();
}
@AfterTest
public void endReport() throws IOException {
extent.flush();
extent.close();
}
My test project is for Mobile, I am using Testng, version 6.10 for my Java tests, with Appium version 7.0.