How to use ExtentReport in a framework
The other day while I was executing my TestNG test cases in the Selenium WebDriver, all my test cases got executed, and the report also showed correctly. However, I usually don’t find its user interface very friendly especially when it’s about creating reports. That’s when I came across a user friendly reporting tool called ExtentReport.
ExtentReport is an HTML reporting library for Java, which can be used with Selenium WebDriver. We can use this tool within our TestNG automation framework. As an automation tester, it’s expected of you to provide detailed yet reports and present it to the administration group. ExtentReport is a simple to use tool to make excellent execution reports.
Process to Set up ExtentReport:
- Install and set up Java on your system.
- Now setup Eclipse.
- Launch Eclipse and create a Maven project.
- Add Selenium, TestNG, ExtentReport dependency in the pom.xml file.
ExtentReport dependency in our maven project, use the below snippet:-
Use Case in which we are going to mechanize
- Check the current URL of the web page
- Enter invalid email id in the Sign Up content box
- Click on the Sign Up button
- To verify the error message.
Create a Simple TestNG Script
Following is the code snippet for our use case.
- startTest(“TestCaseName”, “Description”) : It starts the current test.
TestCaseName – It will print the name of the Test Case in the Report.
Description – It will print the description of the Test case.
- assignAuthor(“AuthorName”) : Test case designer name is mentioned here.
- assignCategory(“CategoryName”) : Category of the Test Case displays here.
- log(LogStatus.PASS, “Step details”): It’s a repository which keeps the information about the test cases whether passed or failed.
- endTest(test) : Current test case ends here.
- flush() : Once the session is finished, specifically call the flush method.
- close() : Call this method at the very end in the @AfterSuite annotation, it ought to be called just once.
Following is the ‘extent-config.xml’ snippet.
Once the test cases are run successfully, the report will be created under your folder. Now, go to the folder and view the .html report.
For e.g.: The path of the report will be D:\MyExtentReport.html
ExtentReport Architecture
After executing the test cases, the ExtentReport design will look like this.
In this report, the main page is the dashboard where:-
- You can view the total number of test cases and test steps
- Start time and End time are displayed
- Number of test cases passed, failed, skipped, and so on information is provided
- Number of steps of test cases passed, failed, and so on data is given
- Pass Percentage of total number of test cases is given
- Category Name of the test cases is likewise shown on the dashboard.
Clicking on the middle tab, I will be able to see the suite level information and its status (whether it’s pass or fail). On clicking the respective test case name, it will show the test case details: its start time, end time and execution time.
Points of interest of ExtentReport
- Open source reporting library.
- Provide delightful and responsive UI.
- Gives dashboard to the whole run.
- Exceptionally easy to utilize API.
- Effortlessly coordinate test-runner logs.
- Parallel execution of classes and strategies upheld.
- It can also be configured on Jenkins server.
It’s a useful storehouse having an extraordinary HTML reporting feature. Automation Testers ought to utilize this report because of its effective reporting by which anybody can understand easily which test case is working appropriately and which falls flat.
HAPPY TESTING!
Hi Kimi,
For our project, we are using cucumber-spring framework. I am able to execute the project and all the scripts are executed successfully but no extent report is generated.
Your help is much appreciated that if you can let me know what is missing in this and why the report is not generated
compile ‘com.sitture:cucumber-jvm-extentreport:3.1.0’ have added under the dependency
classpath “com.sitture:cucumber-jvm-extentreport:3.1.0” as classpath
Have added extent-config.xml under src->resources folder
Have added plugin as
@cucumberoptions(features = “classpath:features”, glue = “”,
plugin = “com.sitture.ExtentFormatter:/build/reports/cucumber/extent-report/extent.html”)
Under the Runner class
ExtentReporter.setConfig(new File(“/src/test/resources/extent-config.xml”));
Can someone share any custom solution available to include Actual and Expected results against each step?
I am using cucumber , serenity-bdd with gradle. Kindly below build.gradle file which i am using. Kindly help me to resolve my issue. I am new to cucumber and tried almost all possible options even i have generated report using maven with cucumber file but facing below issue with gradle and cucumber. I am also using serenity-bdd but i want to use extent report for generating report because i think with serenity we need to stick to steps library.
Can someone please help me to resolve my issue? I have provided all options.
**Step Definition file:**
package Runner;
import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
/**
* A sample test to demonstrate
*/
@RunWith(Cucumber.class)
@CucumberOptions(
features = “src/test/resources/features”
,glue= {“stepDefinition”},
plugin = {“com.cucumber.listener.ExtentCucumberFormatter:”}
)
public class TestRunner {
@BeforeClass
public static void setup() {
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath(“output/myreport.html”);
}
}
**Gradle Build file**
testCompile(
‘net.serenity-bdd:serenity-core:1.8.6’,
‘net.serenity-bdd:serenity-junit:1.8.6’,
‘net.serenity-bdd:serenity-cucumber:1.6.7’,
‘net.serenity-bdd:serenity-report-resources:1.8.6’,
‘net.serenity-bdd:serenity-screenplay-webdriver:1.8.6’,
‘org.assertj:assertj-core:3.8.0’,
‘io.codearte.jfairy:jfairy:0.5.9’,
‘ch.qos.logback:logback-classic:1.2.3’,
‘io.rest-assured:json-path:3.0.0’,
‘io.rest-assured:rest-assured:3.0.0’,
‘io.rest-assured:xml-path:3.0.0’,
‘info.cukes:gherkin:2.12.2’
**Issue Log:**
cucumber.runtime.CucumberException: Couldn’t load plugin class: com.cucumber.listener.ExtentCucumberFormatter. It does not implement cucumber.api.Plugin
at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:179)
at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:166)
at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:223)
at cucumber.runtime.formatter.PluginFactory.isFormatterName(PluginFactory.java:201)
at cucumber.runtime.RuntimeOptionsFactory.addPlugins(RuntimeOptionsFactory.java:94)
at cucumber.runtime.RuntimeOptionsFactory.buildArgsFromOptions(RuntimeOptionsFactory.java:41)
at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:26)
at cucumber.api.junit.Cucumber.(Cucumber.java:74)
Hello,
With Selenium,I need source code of test case execution report step by step.Like if we have 5 steps,So in report:Step Number,Step Description,Expected Result and Status(Pass or Fail) should be displayed.
Thanks,
Amit Agrawal
Hi Kimi,
I am facing an issue where my eclipse shows that the test has passed but the extent report shows the status as Unknown.
I am using endTest and Flush in the @AfterSuite as below:
@AfterSuite
public void endTest() {
extent.endTest(test);
extent.flush();
}
I am using Extent Report version 2.41.2
@BeforeMethod
public void beforeMethod(Method result) {
test = extent.startTest(this.getClass().getSimpleName() + “::” + result.getName(), result.getName());
test.assignAuthor(“Amol Nawale”);
test.assignCategory(“Sanity Test”);
test.log(LogStatus.INFO, result.getName() + “: Test Started”);
}
Can you please check where am I going wrong and why the Unknown is cropping up in the extentReport?
Hi Kimi,
I am facing an issue where my eclipse shows that the test has passed but the extent report shows the status as Unknown.
I am using endTest and Flush in the @AfterSuite as below:
@AfterSuite
public void endTest() {
extent.endTest(test);
extent.flush();
}
I am using Extent Report version 2.41.2
My @BeforeMethod is as below:
@BeforeMethod
public void beforeMethod(Method result) {
test = extent.startTest(this.getClass().getSimpleName() + “::” + result.getName(), result.getName());
test.assignAuthor(“Amol Nawale”);
test.assignCategory(“Sanity Test”);
test.log(LogStatus.INFO, result.getName() + “: Test Started”);
}
Can you pls tell me how to implement the above mentioned example in you blog using testng listeners..
Hi..
This is really nice forum and there is lot of information available.I am hoping I get some help through this.
I would like to take my report directly to dashboard , for now report is taking me to Test-view by default.
I have tried the below options and they did not help me.
String js = “![CDATA[$(document).ready(function() {$(‘.dashboard-view’).click(); });]]>”;
htmlReporter.config().setJS(js);
Can you help me with this please.
Thanks,
Suresh
Hello,
I am getting the below error.Could you please help me?
java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
Can you please share the config file too.Thanks a lot for the detailed explanation.It is really helpful.
Please find the attached snippet for ‘extent-config.xml’ in my blog it might help you.
I want to generate test results in Extent Reports. My requirements is for Parallel execution. Each testsuite has same cases and executes in parallel mode. Now I want to see the both testsuite results in Extnet reports. Is there any way to view both TestSuite results in one Extent report?
Please help me. Thank you!
Here screenshots are getting stored at local folder which html report refers.
If I want to share these reports with someone, how he would be see the screenshots in that case.
I have issue with ‘extent reports’ display in the browser. Our proxy server doesn’t allow the sites to render Java script and CSS. How can I work around this? Are you familiar with any security threats using this ‘extent reports’?
Can you explain about extent-config.xml.
Can you please share this file as well?
‘extent-config.xml’ helps us in customizing our report file.
Please find the attached snippet for ‘extent-config.xml’ in my blog it might help you.
Is there some similar framework for protractor?
Thanks in advance.
For Protractor, you can design your report using Allure Reporting. ExtentReport is not supported for the JavaScript project.
Wonderful explanation and review of extentreport. I certainly enjoyed it. It would have been one point solution for me if has covered mailing of this report to business/team post execution. But nevertheless, v. good effort to have very detail review of the report and hope to have many more articles. Cheers !
how to add more than one test to extent reports.
As you can see the ‘TestNG Script’. So in that script, you can add more than one Test method then you will be able to see the result in ExtentReport.
I am getting an exception while creating an instance of ExtentReports
*********
extent = new ExtentReports(“C:\\Selenium_Luna\\MyMaven_DataDrivenFramework\\reports\\”+fileName, true, DisplayOrder.NEWEST_FIRST);
****************************
org.testng.TestNGException:
Cannot instantiate class com.selenium.testng.ddf.testcases.LoginTest
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:363)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:275)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
at org.testng.TestClass.getInstances(TestClass.java:100)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:86)
at org.testng.TestClass.init(TestClass.java:78)
at org.testng.TestClass.(TestClass.java:41)
at org.testng.TestRunner.initMethods(TestRunner.java:425)
at org.testng.TestRunner.init(TestRunner.java:252)
at org.testng.TestRunner.init(TestRunner.java:222)
at org.testng.TestRunner.(TestRunner.java:171)
at org.testng.remote.support.RemoteTestNG6_10$1.newTestRunner(RemoteTestNG6_10.java:28)
at org.testng.remote.support.RemoteTestNG6_10$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_10.java:61)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:623)
at org.testng.SuiteRunner.init(SuiteRunner.java:189)
at org.testng.SuiteRunner.(SuiteRunner.java:136)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1375)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1355)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
… 25 more
Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.relevantcodes.extentreports.Configuration.getConfigurationMap(Configuration.java:38)
at com.relevantcodes.extentreports.Report.loadConfig(Report.java:445)
at com.relevantcodes.extentreports.Report.(Report.java:566)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:66)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:362)
at com.selenium.testng.ddf.basetest.ExtentManager.getInstance(ExtentManager.java:24)
at com.selenium.testng.ddf.basetest.BaseTest.(BaseTest.java:41)
at com.selenium.testng.ddf.testcases.LoginTest.(LoginTest.java:17)
… 30 more
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 60 more
Please use this.
String workingDir = System.getProperty(“user.dir”);
System.out.println(“Current working directory : ” + workingDir);
extent = new ExtentReports(workingDir+”/Test_Execution_Report.html”, true,DisplayOrder.NEWEST_FIRST);
extent.loadConfig(new File(workingDir+”/extent-config.xml”));
can u sent simple program for ExtentReports
You can use this script.
package com.DoTrips;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class Demo {
public static ExtentReports extent;
public static ExtentTest test;
public static void main(String []args){
extent = new ExtentReports(“D://Report//advanceExtentReport.html”,true);
ExtentTest test = extent.startTest(“My First Test”, “Sample description”);
test.log(LogStatus.PASS, “hello test”);
extent.endTest(test);
extent.flush();
}
}