У меня работает нижеприведенный код для отчета об объеме. Попробуйте!
1) Инициализировать отчет об объеме и Logger
public static Logger log = Logger.getLogger("devpinoyLogger");
public ExtentReports rep = ExtentManager.getInstance();
public static ExtentTest test;
2) Используйте файл конфигурации ReportsConfig.xml для отчета по экстентам, который вы можете получить на официальном сайте.
3) Создайте класс ExtentManager, который загружает файл конфигурации и настраивает вывод файла отчета Extent.
public class ExtentManager {
private static ExtentReports extent;
public static ExtentReports getInstance(){
if(extent==null){
System.out.println("Path of user DIR"+System.getProperty("user.dir"));
extent = new ExtentReports(System.getProperty("user.dir")+"\\target\\surefire-reports\\ExecutionReport.html",true,DisplayOrder.OLDEST_FIRST);
extent.loadConfig(new File(System.getProperty("user.dir")+"\\src\\main\\java\\extentconfig\\ReportsConfig.xml"));
}
return extent;
}
}
4) Используйте метод регистрации INFO и ERROR в создаваемом вами методе для отображения журналов в отчете Extent.
public void click(String xpath) {
try {
driver.findElement(By.xpath(Variables.OR.getProperty(xpath))).click();
System.out.println(xpath + "Button clicked");
test.log(LogStatus.INFO, xpath + " Button clicked");
Thread.sleep(1000);
} catch (Exception e) {
System.err.println("Cannot Click " + e.getMessage());
test.log(LogStatus.ERROR,"Unable to click on :: " + xpath + " Button");
throw new AssertionError("Unable to click on :: " + xpath + " Button", e);
}
}
5) Использовать пользовательский класс прослушивателя CustomListeners
public class CustomListeners extends TestBase implements ITestListener, ISuiteListener {
public boolean flag;
..implement all methods of CustomListeners class and use logs in onTestSuccess and onTestFailure Methods.
public void onTestSuccess(ITestResult arg0) {
test.log(LogStatus.PASS, arg0.getName().toUpperCase() + " PASS");
rep.endTest(test);
rep.flush();
}
public void onTestFailure(ITestResult arg0) {
System.out.println(arg0 + " =================Test Case Failed===========================");
flag = true;
System.out.println("Flag is inside onTestFailure " + flag);
System.setProperty("org.uncommons.reportng.escape-output", "false");
try {
test.log(LogStatus.FAIL, arg0.getName().toUpperCase() + " Failed with exception : " + arg0.getThrowable());
rep.endTest(test);
rep.flush();
} catch (IOException e) {
System.err.println("IOException occurs " + e.getMessage());
e.printStackTrace();
}
}
}
- Представление ExtentReport для теста PASS
- Представление ExtentReport для теста FAIL