When I add listeners in testng.xml, the extent reports for only first suite is getting displayed. Below is my listener and test base classes:
public class TestBase {
public ExtentTest test;
public static ExtentReports reports;
public SoftAssert softAsserts;
@BeforeMethod(alwaysRun = true)
public void init(ITestResult results) {
reports = ExtentManager.getReports();
test = reports.createTest(results.getMethod().getMethodName().toUpperCase());
results.setAttribute("reporters" , test);
softAsserts = new SoftAssert();
}
@AfterMethod(alwaysRun = true)
public void exit() {
System.out.println("Calling @AfterMethod");
reports.flush(); //Generates the reports
}
public void log(String msg) {
System.out.println(msg);
test.log(Status.INFO, msg);
}
public void logFailure(String msg) { // only fails in extent reports
System.out.println(msg);
test.log(Status.FAIL, msg);
}
public void failAndStopTest(String msg) {
logFailure(msg);// this prints from extent report
softAsserts.fail(msg);// this prints from testng
softAsserts.assertAll();//stop
}
public void softAssertMethod(String msg) { //this is in extent reports and testng
logFailure(msg);//extent
softAsserts.fail(msg);//testng
}
}
public class CustomListeners implements ITestListener{
public void onTestFailure(ITestResult result) {
System.out.println("-----Test Failed-------");
System.out.println("Failed Test case name :"+result.getName());
System.out.println("Status of the test case:"+result.getStatus());
System.out.println(result.getThrowable().getMessage());
ExtentTest test = (ExtentTest)result.getAttribute("reporters");
test.log(Status.FAIL, result.getThrowable().getMessage());
}
public void onTestSuccess(ITestResult result) {
System.out.println("------Test Passed------");
ExtentTest test = (ExtentTest)result.getAttribute("reporters");
System.out.println("Passed Test Case Name :"+result.getName());
test.log(Status.PASS, result.getThrowable().getMessage());
}
public void onTestSkipped(ITestResult result) {
System.out.println("------Test Skipped------");
ExtentTest test = (ExtentTest)result.getAttribute("reporters");
System.out.println("Passed Test Case Name :"+result.getName());
test.log(Status.SKIP, result.getThrowable().getMessage());
}
}