How To Generate Extent Reports Version 3 in Selenium WebDriver
Generate Extent Reports Version 3 in Selenium WebDriver
Earlier we posted “How To Generate Extent Reports” and in that post, we used version 2 of extent reports. This post will guide you on “How To Generate Extent Reports Version 3 in Selenium“. Extent reports are the advanced Selenium Reporting Tool.
By default, TestNG generates a report. A small note on how to generate reports using TestNG. Once you execute your tests, TestNG generates a test-output folder at the root of your project. It contains a detailed report and a summary report. But to get an advanced selenium report, you need to go for Extent Reports. If you still, want to see how TestNG Reports look like – click here to see the TestNG Report in Selenium
Now lets move on to advanced selenium reports i.e., Extent Reports.
Pre-requisites to Advanced Selenium Reporting – Generate Extent Reports:
- Java should be installed (Link to Install and setup Java )
- TestNG should be installed (Link to Install TestNG )
- Extent Report Version 3 Jars – Download
- extent-config.xml – It allows to configure HTML Report
Steps To Generate Extent Reports:
- Firstly, create a TestNG project in eclipse
- Now download extent library files from the following link: https://extentreports.com/
- Add the downloaded library files to your project
- Create a java class say ‘ExtentReportsClass’ and add the following code to it
Code explanation is clearly given in the earlier post “How To Generate Extent Reports Version 2”
package extentReports; import org.testng.Assert; import org.testng.ITestResult; import org.testng.SkipException; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.Status; import com.aventstack.extentreports.markuputils.ExtentColor; import com.aventstack.extentreports.markuputils.MarkupHelper; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; import com.aventstack.extentreports.reporter.configuration.ChartLocation; import com.aventstack.extentreports.reporter.configuration.Theme; public class ExtentReportsClassVersion3{ ExtentHtmlReporter htmlReporter; ExtentReports extent; ExtentTest logger; @BeforeTest public void startReport(){ htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/STMExtentReport.html"); extent = new ExtentReports (); extent.attachReporter(htmlReporter); extent.setSystemInfo("Host Name", "SoftwareTestingMaterial"); extent.setSystemInfo("Environment", "Automation Testing"); extent.setSystemInfo("User Name", "Rajkumar SM"); htmlReporter.config().setDocumentTitle("Title of the Report Comes here"); htmlReporter.config().setReportName("Name of the Report Comes here"); htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP); htmlReporter.config().setTheme(Theme.STANDARD); } @Test public void passTest(){ logger = extent.createTest("passTest"); Assert.assertTrue(true); logger.log(Status.PASS, MarkupHelper.createLabel("Test Case Passed is passTest", ExtentColor.GREEN)); } @Test public void failTest(){ logger = extent.createTest("failTest"); Assert.assertTrue(false); logger.log(Status.PASS, "Test Case (failTest) Status is passed"); logger.log(Status.PASS, MarkupHelper.createLabel("Test Case (failTest) Status is passed", ExtentColor.GREEN)); } @Test public void skipTest(){ logger = extent.createTest("skipTest"); throw new SkipException("Skipping - This is not ready for testing "); } @AfterMethod public void getResult(ITestResult result){ if(result.getStatus() == ITestResult.FAILURE){ //logger.log(Status.FAIL, "Test Case Failed is "+result.getName()); //MarkupHelper is used to display the output in different colors logger.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + " - Test Case Failed", ExtentColor.RED)); logger.log(Status.FAIL, MarkupHelper.createLabel(result.getThrowable() + " - Test Case Failed", ExtentColor.RED)); }else if(result.getStatus() == ITestResult.SKIP){ //logger.log(Status.SKIP, "Test Case Skipped is "+result.getName()); logger.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + " - Test Case Skipped", ExtentColor.ORANGE)); } } @AfterTest public void endReport(){ extent.flush(); } }
extent-config.xml:
<?xml version="1.0" encoding="UTF-8"?> <extentreports> <configuration> <!-- report theme --> <!-- standard, dark --> <theme>standard</theme> <!-- document encoding --> <!-- defaults to UTF-8 --> <encoding>UTF-8</encoding> <!-- protocol for script and stylesheets --> <!-- defaults to https --> <protocol>https</protocol> <!-- title of the document --> <documentTitle>Extent</documentTitle> <!-- report name - displayed at top-nav --> <reportName>Automation Report</reportName> <!-- location of charts in the test view --> <!-- top, bottom --> <testViewChartLocation>bottom</testViewChartLocation> <!-- custom javascript --> <scripts> <![CDATA[ $(document).ready(function() { }); ]]> </scripts> <!-- custom styles --> <styles> <![CDATA[ ]]> </styles> </configuration> </extentreports>
Refresh the project after execution of the above ExtentReportsClassVersion3.java file. You could find an HTML file named “STMExtentReport.html” in your test-output folder. Copy the location of the STMExtentReport.html file and open it by using any browser. You could see beautiful high rich HTML reports as shown below.
Test Summary Report:
Graphical Report with PIE Charts:
Check this post to learn “How To Insert Captured Screenshots in Extent Reports“
If you have any queries, please comment below. Like this post, don’t forget to share it.
Hi Raj,
Does Extent Report support multiple suite reports in a Single report.
Say, I have 3 suites and all the 3 TestNG suites were in my pom.xml and I will be kicking the pom.xml for running my suites.
My query is, I want to have all the tests info in a single Extent Report.
@BeforeSuite
public static void startReport() {
String name = “C://Reports//TestAutomationResults -” + getDate();
System.out.println(“HTML REPORT LOCATION IS :: ************* ” + name);
extent = new ExtentReports(name + “.html”, false);
extent.addSystemInfo(“Host Name”, “CABS”)
.addSystemInfo(“Environment”, “QA”)
extent.loadConfig(new File(System.getProperty(“user.dir”) + “\\extent-config.xml”));
}
Please let me know If I am not clear
How do we get Pass percentage in DashBoard??
Configure Extent Report in Before and After Suites. That will work
Thanks Gurudatta
Can this be used without TestNG project ? If so , can you please guide me .I am getting the error message “The method setSystemInfo(String, String) is undefined for the type ExtentReports”
Please post your code.
Hi Rajkumar ,
I was able to fix that issue .My class name was also ExtentReports and hence was facing this issue .Once i renamed the class , it worked fine .
I have two more questions :
-> test..log(Status.PASS, MarkupHelper.createLabel(result, ExtentColor.GREEN));
How to pass some more arguments in the above command . I want to show the Step Description and the Actual Result. Now it is allowing me to pass only one argument in addition to the status
-> Time Taken in Dashboard is displayed in “ms” .Can we display that in hh:mm:ss format?
Hi Ganesh, MarkupHelper accepts only two parameters… Check the official extent reports documentation
Thanks Rajkumar for the response . Do have an idea about the 2nd query
-> Time Taken in Dashboard is displayed in “ms” .Can we display that in hh:mm:ss format?
Not getting where we need to put our test code in the extent report?
In other words, I am not getting how can I get results of my tests?
I am new to it and using page object framework (from toolsqa website). Can I use this extent report code for my page object structure?
Hi Amit, you can use extent reports. Place @BeforeTest and @AfterMethod in your base class and call logger wherever it is necessary in your test scripts.
Thanks,
Rajkumar
Thanks Raj….its working now for individual tests (when running as TestNG), generating report successfully. 🙂
Now tried a lot to run it for multiple tests, it’s not working. I had already changed @BeforeTest and @AfterTest to @BeforeSuite and @AfterSuite respectively.
My TestNG is-
When I ran it as a suite, 1st test get passed, 2nd gets failed and 3rd test gets skipped (all 3 tests contains same code of login, just replicas of each other) with no extent report gets generated.
If I put Test1_TC at first place and SignIn_TC at second place, it gives same results (1st-passed, 2nd-failed, 3rd-skipped )
Please help.
testng.xml contains-
Hi Amit, replace < and > with ? in testng.xml and send…
?class name=”testCases.SignIn_TC” /?
?class name=”testCases.Test1_TC” /?
?class name=”testCases.SearchaStore_TC” /?
Hi Amit, Send your project to rajkumarsmonline [at] gmail [dot] com
Hi Raj,
Details shared on your email id. Please take a look and help.
Thanks in advance.
did you get my question listed ? I do not see my question listed?
Whats your question Asif
Hi,
Thank you for your tutorial. It is extremely helpful. When I am executing Extent Reports. I am getting error message. See my code below.
I tried posting the code. but I am unsuccessful.
Pls send an email to rajkumarsmonline@gmail.com
did you get a chance to look at my Issue.? I need help with this please. ????
Hi Asif
No, It is not getting created at that location. I have the correct code. But did you take a look at my code. I am getting a stack trace message. The location is specified correctly in the code. Something else is wrong. Maybe I am missing some jars.????
You cannot pass location this way..
htmlReporter = new ExtentHtmlReporter(System.getProperty(“user.dir”) + “C:\\selenium\\extent_reports\\STMExtentReport.html”);
Change the above statement.
htmlReporter = new ExtentHtmlReporter(System.getProperty(“user.dir”) + “/test-output/STMExtentReport.html”);
I was able to fix my Issue. I did not all the JAR files installed in my eclipse. It is all working now.
thanks in advance
Hi ,
How do i intergrate this with my test cases? can u please help.
Hi Sowmya, please go through the comments section, I have explained to someone earlier.