While working with Selenium automation testing, we use different 3rd party frameworks (TestNG, Junit, MBunit, Nunit) in combination with Java or .NET to report the result at the end of the test execution or we use our own dashboard/html kind of reports,
While browsing different ways of reporting, got web links of ExtentReports, most of the links talk about the version 1.x,
but when I looked into the original web link http://extentreports.relevantcodes.com by AnsooArora, it’s upgraded to 2.x, this is something different approach (in configuration wise) than the earlier version 1.x
Usage documentation link – http://extentreports.relevantcodes.com/java/#basic-usage
Let’s see some of the highlights of the latest version 2.x (till now),
Note: we will see the implementation with selenium and Java.
Update –
For extent report version 3.x, please follow Selenium reporting using extent report ver 3.x
Download the jar file from the below location
http://extentreports.relevantcodes.com/ (Click on Download extent for Java)
Extract and add the extentreports-java-2.03.jar file along all required Selenium *.jar files in Eclipse Java Build Path.
We will directly move to the code part and then will see details about each statement, and will see the result report at the end.
Have 3 separate class files,
Class1
public class ExtentManager { public static ExtentReports Instance() { ExtentReports extent; String Path = "./ExtentReport.html"; System.out.println(Path); extent = new ExtentReports(Path, false); extent.config() .documentTitle("Automation Report") .reportName("Regression"); return extent; } public static String CaptureScreen(WebDriver driver, String ImagesPath) { TakesScreenshot oScn = (TakesScreenshot) driver; File oScnShot = oScn.getScreenshotAs(OutputType.FILE); File oDest = new File(ImagesPath+".jpg"); try { FileUtils.copyFile(oScnShot, oDest); } catch (IOException e) {System.out.println(e.getMessage());} return ImagesPath+".jpg"; } }
—————————— Update: Extent version 2.40 on wards ———————————
Following code may not work
extent.config() .documentTitle("Automation Report") .reportName("Regression");
Now you can load config.xml file into the code, so manually change the xml file and load it at run time.
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>ExtentReports 2.0</documentTitle> <!-- report name - displayed at top-nav --> <reportName>Automation Report</reportName> <!-- report headline - displayed at top-nav, after reportHeadline --> <reportHeadline></reportHeadline> <!-- global date format override --> <!-- defaults to yyyy-MM-dd --> <dateFormat>yyyy-MM-dd</dateFormat> <!-- global time format override --> <!-- defaults to HH:mm:ss --> <timeFormat>HH:mm:ss</timeFormat> <!-- custom javascript --> <scripts> <![CDATA[ $(document).ready(function() { }); ]]> </scripts> <!-- custom styles --> <styles> <![CDATA[ ]]> </styles> </configuration> </extentreports>
Syntax – let’s say config file name is – extent-config.xml
loadConfig(new File("./extent-config.xml"));
———————————————————————————————————–
Class2 : Testcase 1
public class TC1 { ExtentReports extent; ExtentTest test; WebDriver driver; @BeforeClass public void M1(){ extent = ExtentManager.Instance(); driver = new FirefoxDriver(); } @Test public void OpenAUT() { try{ driver.get("http://www.qavalidation.com/"); test = extent.startTest("OpenUT", "Verify HomePage"); if(driver.getTitle().contains("QA & Validation")) test.log(LogStatus.PASS, driver.getTitle() +" contain "+"QA & Validation" ); else test.log(LogStatus.FAIL, driver.getTitle() +" doesn't contain "+"QA & Validation" ); }catch(Exception e){test.log(LogStatus.ERROR, e.getMessage());} } @AfterClass public void tear() { extent.endTest(test); extent.flush(); extent.close(); driver.quit(); } }
Class3: TestCase2
public class TC2 { ExtentReports extent; ExtentTest test; WebDriver driver; @BeforeClass public void M1(){ extent = ExtentManager.Instance(); driver = new FirefoxDriver(); } @Test public void M3() { try{ test = extent.startTest("ContactPage", "Verify Send button"); driver.get("http://www.qavalidation.com/"); Assert.assertTrue(driver.getTitle().contains("QA & Validation")); test.log(LogStatus.INFO, "site opened"); driver.findElement(By.linkText("Contact!")).click(); Thread.sleep(2000); WebElement Send = driver.findElement(By.id("ContactForm1_contact-form-submit")); if(Send.isDisplayed()) {test.log(LogStatus.PASS, Send.getAttribute("Value")+" button Found"); test.log(LogStatus.INFO, test.addScreenCapture(ExtentManager.CaptureScreen(driver, "./Send"))); } else {test.log(LogStatus.FAIL, Send.getAttribute("Value")+" button NOT Found" );} }catch(Exception e){test.log(LogStatus.ERROR, e.getMessage());} } @AfterClass public void tear() { extent.endTest(test); extent.flush(); extent.close(); driver.quit(); } }
Now create testNG.xml to run the above 2 test cases…
<suite name="Suite" parallel="none"> <test name="Test"> <classes> <class name="pkg.TC1"/> <class name="pkg.TC2"/> </classes> </test> </suite>
ExtentReports.html file will be created under your project folder.
Open this file, in browser and observe a nice result report of your test run.
In details:
ExtentReports extent = new ExtentReports(file-path, replaceExisting, DisplayOrder);
file-path:
path to save the result report (in .htm or .html), dataType : StringreplaceExisting:
true = Replace new file to the existing report
false = append to the existing report if any.
dataType : booleanDisplayOrder:
OLDEST_FIRST – Old tests display on top of the report
NEWEST_FIRST – New tests display on top of the report
extent.config() .documentTitle("Automation Report") .reportName("Regression");
Above is to give some basic information about the report, (this is optional)
extent .addSystemInfo("Selenium Version", "2.46") .addSystemInfo("Environment", "QA");
This above is will display on the report, this is optional.
Now, in each testcase –
- extent = ExtentManager.Instance();
getting the Extentreports object instance.
- test = extent.startTest(“OpenUT”, “Verify HomePage”);
Write the startTest to initialize the ExtentTest object.
- For pass scenarios: test.log(LogStatus.PASS, details);
- For fail scenarios: test.log(LogStatus.FAIL, details);
- For info : test.log(LogStatus.INFO, “site opened”);
Depending on the Pass, Fail, Info, Warning and Error – Result report shows with different colored annotations for quick look.
- As we did, extent.startTest, at the end of test run, we need to do extent.endTest(test);
- extent.flush();
To write all above steps, status, details to html
Even we can have screenshots embed inside the report,
test.log(LogStatus.INFO, test.addScreenCapture(ExtentManager.CaptureScreen(driver, “./Send”)));
Means,
test.log(LogStatus.INFO, test.addScreenCapture(String path));
We need to write login to get the image path, which we written in ExtentManager class.
More details about How to enter information about System Configuration and environment details in terms of Map, category wise test run, inserting HTML content, you can refer http://extentreports.com/
when i use 2.10 extent jar the report shows like only 2 tabs in the menu if i add category (smoke) then seeing 3 tabs under menu section………
— is there any possibility to add an image of Project with small icon at top right or left
— is there any way to hide the default host name and java version on Pie Chart below thing.
— is Jenkins support this report or any reports are there which supports for jenkins.
hi
when creating extent instance
if (extent == null) {
extent = new ExtentReports(filePath, true);
i got this error
java.lang.NoSuchFieldError: VERSION_2_3_23
at com.relevantcodes.extentreports.HTMLReporter.start(HTMLReporter.java:75)
at com.relevantcodes.extentreports.Report.attach(Report.java:302)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:78)
at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:362)
at extentFadi.ex.ExtentManager.Instance(ExtentManager.java:20)
any help please
ITs very useful thank you
I am using TestNG framework which got integrated with jenkins, i wanted to have Extent report in jenkins, is it possible? could you please guide how can i get Extentreport in jenkins
L V Prasad, I din’t integrate yet with jenkins, but there shouldn’t be any more configuration needed with jenkins, how we are getting testNG reports in jenkins, same way we should see extent reports, just add extent report to ur existing project and run in jenkins..
Hi,
Very nice article on extent report. I have one doubt here, could you please clarify here.
in Method M3, when element is not displayed why it is going to else block not getting executed it is directly going to catch.
WebElement Send = driver.findElement(By.id(“ContactForm1_contact-form-submit”));
if(Send.isDisplayed())
{test.log(LogStatus.PASS, Send.getAttribute(“Value”)+” button Found”);
test.log(LogStatus.INFO, test.addScreenCapture(ExtentManager.CaptureScreen(driver, “./Send”)));
}
else
{test.log(LogStatus.FAIL, Send.getAttribute(“Value”)+” button NOT Found” );}
}catch(Exception e){test.log(LogStatus.ERROR, e.getMessage());
I tried above code by remove try catch block. Still it is not going to else block when element is not displayed but it is going if block when element is displayed.
In report.html status is showing as Unknown instead Fail when element is not found but status is showing as pass when element is found.
When driver.findElement(By.id(“ContactForm1_contact-form-submit”)); not able to find the element, it will not go to else block as the object Send = null and it stops executing next line, it never even checks your if condition …
You need to create a method to identify the webElement, if it’s not null then only proceed with your rest of code..
public static WebElement Send(WebDriver driver){
try{
element = driver.findElement(By.id(“ContactForm1_contact-form-submit”));
return element;
}catch(Exception e){return null;}
}
————————————–
Now check if(Send != null && Send.isDisplayed())
//proceed with your code
Hi,
Well done for the good work, however, I tried to implement ExtentReports on Ubuntu 16.04 with the Selenium Webdriver IDE and the necessary plugins. The test ran successfully but the Report html failed to be displayed rather this is what I got:
ExtentReports 2.0
ExtentReports
Test Details
Categories
Exceptions
Analysis
TestRunner Logs
Automation Report
2016-09-19 22:57:50
v2.41.0
Total Tests
Total Steps
Total Time Taken (Current Run)
0h 43m 5s+671ms
Total Time Taken (Overall)
0h 0m 45s+874ms
Start
2016-09-19 22:14:45
End
2016-09-19 22:57:50
Tests View
test(s) passed
test(s) failed, others
Steps View
step(s) passed
step(s) failed, others
Pass Percentage
Environment
Param
Value
User Name
lTest2
OS
Linux
Java Version
1.8.0_91
Host Name
lTest2-Aspire-5733
Ubuntu
16.04LTS
Tests
Pass
Fail
Skip
Clear Filters
·
·
Test1VerifyMyPageTitle
fail
2016-09-19 22:14:45
2016-09-19 22:15:04
0h 0m 19s+0ms
Test1
Test2
Status
Timestamp
Details
22:15:02
Browser Started
22:15:04
Application is up and running
22:15:04
Test1VerifyMyPageTitle
fail
2016-09-19 22:43:34
2016-09-19 22:43:38
0h 0m 4s+0ms
Test1
Test2
Status
Timestamp
Details
22:43:37
Browser Started
22:43:38
Application is up and running
22:43:38
Test1VerifyMyPageTitle
fail
2016-09-19 22:46:33
2016-09-19 22:46:38
0h 0m 5s+0ms
Test1
Test2
Status
Timestamp
Details
22:46:36
Browser Started
22:46:37
Application is up and running
22:46:38
Test1VerifyMyPageTitle
fail
2016-09-19 22:53:58
2016-09-19 22:54:03
0h 0m 5s+0ms
Test1
Test2
Status
Timestamp
Details
22:54:01
Browser Started
22:54:02
Application is up and running
22:54:03
Test1VerifyMyPageTitle
pass
2016-09-19 22:57:19
2016-09-19 22:57:23
0h 0m 4s+0ms
Test1
Test2
Status
Timestamp
Details
22:57:22
Browser Started
22:57:23
Application is up and running
22:57:23
Title verified
Test1VerifyMyPageTitle
pass
2016-09-19 22:57:45
2016-09-19 22:57:50
0h 0m 4s+405ms
Test1
Test2
Status
Timestamp
Details
22:57:49
Browser Started
22:57:50
Application is up and running
22:57:50
Title verified
Configure Tests Count Setting
Parent Tests Only (Does not include child nodes in counts)
Parent Tests Without Child Tests + Child Tests
Child Tests Only
Save
Select status
Pass
Fail
Fatal
Error
Warning
Skipped
Info
Unknown
Save
jQuery(document).ready(function() { jQuery(‘.logo span’).html(‘ExtentReports’); });
$(document).ready(function() {
});
Please let me know what I am doing wrong. Could it be some server security issue or some plugins missing?
Cheers,
Lawrence
Hello,
I am not able to get the Jar. The link mentioned is blank.
Could you please provide the same.
Thanks Hanumant,
The Jar file is ExtentReports 2.41.1
I noticed that when the html file was copied out and opened in another directory, it displayed normally.
Many thanks,
Lawrence
Hi,
I’m not too sure why I keep having this error with the CucumberExtentReports and all effort to get it resolved has proved abortive. Please find the error message below:
java.lang.NullPointerException at com.cucumber.listener.ExtentCucumberFormatter.close(ExtentCucumberFormatter.java:219)
I have consulted some of the articles written online with no relief. I will appreciate it if somebody can help proffer solution to this.
Many thanks,
Lawrence
Hello Ajay,
I am using extentreports-2.03.jar and followed your test and used all the test.log(LogStatus.Pass and all accordingly , everything was working fine but when I tried to use test.log(LogStatus.SKIP). its returning pass in the test report it’s just showing test step skip in the detail view.
My before class code is as mentioned below. I read this is known issue that the developer wanted to make is as it is he made skip priority low. So I think he fixed it but I am not able to make it. Could you please help.
if(!TestDataToRun[DataSet].equalsIgnoreCase(“Y”)){
Add_Log.info(“TestCase-” + TestCaseName + “_TestName “+ TestName+” : DataToRun = N for data set line “+(DataSet+1)+” So skipping Its execution.”);
Testskip=true;
test.log(LogStatus.SKIP , TestName+” : CaseToRun = N for So Skipping Execution.”);
Add_Log.info(“TestCase-” + TestCaseName + “_TestName “+ TestName + ” : Reporting test data set line “+(DataSet+1)+” as SKIP In excel.”);
SuiteUtility.WriteResultUtility(FilePath, TestCaseName, “Pass/Fail/Skip”, DataSet+1, “SKIP”);
throw new SkipException(“DataToRun for row number “+DataSet+” Is No Or Blank. So Skipping Its Execution.”);
}
Hi Hanumant,
I’m not too sure of the problem you described and I did not post any test but, some problems I came across in my test executions. However, I will suggest you use the latest version of extentreports jar which as I’m writing is extentreports 2.41.1 jar. It can be found from the Maven repository.
I Wish you the best of luck!
Thanks for report…..
I tried for document title and report name but code shows deprecated. Is there any way to change title and name
extent.config()
.documentTitle(“Automation Report”)
.reportName(“Regression”);
Hi Vinod, which version of extent report you are using?
Hi Sunil
Extent report version is 2.41.0
you can use config.xml to load it runtime, as the setdocumenttitle() may not work
See the updated section of my post.
Let me know if this doesn’t help!
Is there any way to add bar graph in extent reports.
I think this can be possible with extentx.
very nice and precise information on using extent reports. thanks for this educative post.
I want to share these reports with my team mate but since it stores the screenshots in my local machine, he will not be able to see screenshots in the reports. Any work around for this?
Hi Richa,
you have to copy all supporting file to send the report [including the css, js etc], so another person can open the html file, I think extentX is a paid library which will give u a report on cloud…