· Very simple to use API
· Beautiful and responsive UI
· Provides dashboard for the entire run
· Creates a single report file, so less management of artifacts required
· Separate section for categories, provides analysis of tests by category
· Generate Pie Chart based on test case status.
· We can filter reports depending on status.
· It fetches system details like OS, Java Version, and Memory and so on.
· Attach screenshot in the report that is a most important feature.
· Easily integrate test-runner logs
· Can be customized heavily using an external config file
To implment extent report make sure the follwing pre-request
=>The required dependency or jar file can be downloaded from the folowing reosuces
mvnrepository.com/search?q=Extents+report
relevantcodes.com/extentreports-for-selenium/
=>Java should be installed – Install and setup Java
=>TestNG should be installed – Install TestNG
=>extent-config.xml – It allows to configure HTML Report
Why we need Extent report while Selenium comes with JUnit and TestNg report?
This is because, With extent reports, you can offer a more extensive and insightful perspective on the execution of your automation scripts. Extent Reports is a customizable HTML report developed by Anshoo Arora which can be integrated into Selenium WebDriver using JUnit and TestNG frameworks.
The following are the advantages of using Extent report in test automation script:
Extent reports are more customizable than others
Extent API can produce more interactive reports, a dashboard view, graphical view, capture screenshots at every test step, and emailable reports
It can be easily integrated with frameworks like JUnit, NUnit, & TestNG
It displays the time taken for test case execution
Using Extent Reports in Selenium Webdriver
Extent Reports contain two major classes that are used frequently, ExtentReports class and ExtentTest class.
The above classes can be used with the frequently used built-in methods that are stated below.
StartTest, EndTest, Log and Flush
public class ExtentReportsClass {
ExtentReports extent;
ExtentTest logger;
@BeforeTest
public void startReport(){
//ExtentReports(String filePath,Boolean replaceExisting)
//filepath - path of the file, in .htm or .html format - path where your report needs to generate.
//replaceExisting - Setting to overwrite (TRUE) the existing file or append to it
//True (default): the file will be replaced with brand new markup, and all existing data will be lost. Use this option to create a brand new report
//False: existing data will remain, new tests will be appended to the existing report. If the the supplied path does not exist, a new file will be created.
extent = new ExtentReports (System.getProperty("C:\\Users\\Biniyam\\IdeaProjects\\ExtentReport\\test-output") +"/test-output/STMExtentReport.html", true);
//extent.addSystemInfo("Environment","Environment Name")
extent
.addSystemInfo("Host Name", "SoftwareTestingMaterial")
.addSystemInfo("Environment", "Automation Testing")
.addSystemInfo("User Name", "Rajkumar SM");
//loading the external xml file (i.e., extent-config.xml) which was placed under the base directory
//You could find the xml file below. Create xml file in your project and copy past the code mentioned below
extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
}
@Test
public void passTest(){
//extent.startTest("TestCaseName", "Description")
//TestCaseName – Name of the test
//Description – Description of the test
//Starting test
logger = extent.startTest("passTest");
Assert.assertTrue(true);
//To generate the log when the test case is passed
logger.log(LogStatus.PASS, "Test Case Passed is passTest");
}
@Test
public void failTest(){
logger = extent.startTest("failTest");
Assert.assertTrue(false);
logger.log(LogStatus.PASS, "Test Case (failTest) Status is passed");
}
@Test
public void skipTest(){
logger = extent.startTest("skipTest");
throw new SkipException("Skipping - This is not ready for testing ");
}
@AfterMethod
public void getResult(ITestResult result){
if(result.getStatus() == ITestResult.FAILURE){
logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getName());
logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getThrowable());
}else if(result.getStatus() == ITestResult.SKIP){
logger.log(LogStatus.SKIP, "Test Case Skipped is "+result.getName());
}
// ending test
//endTest(logger) : It ends the current test and prepares to create HTML report
extent.endTest(logger);
}
@AfterTest
public void endReport(){
// writing everything to document
//flush() - to write or update test information to your report.
extent.flush();
//Call close() at the very end of your session to clear all resources.
//If any of your test ended abruptly causing any side-affects (not all logs sent to ExtentReports, information missing), this method will ensure that the test is still appended to the report with a warning message.
//You should call close() only once, at the very end (in @AfterSuite for example) as it closes the underlying stream.
//Once this method is called, calling any Extent method will throw an error.
//close() - To close all the operation
extent.close();
}
One of the advantage of an extended report is capturing screenshots. It is recommended to screenshooot when the test is failed because it consumeslotote of space. Screen Capture along with test execution will help a tester in debugging the test script if there are any issues encountered during test execution.