Selenium HTML result reporting using ExtentReports 3.X

selenium-result-reporting-using-extent-reportIn our earlier post (Selenium reporting using extent 2.x), we have seen as a starting point how to generate report at end of test execution using 2.x version.

As extent report is becoming more popular and they are also trying to make it more flexible by providing frequent updates, so in this post, we will be discussing more in detail about the newly release version 3.0 (till now), which is of quite different in configuration (of course, concept remains same :D).

Download the latest released version from the following link (Note: we will be using Java language)

http://extentreports.relevantcodes.com/

  • Extract extent jar file and add to the build path in eclipse project [extentreports-3.0.0.jar]
  • Add all other required (selenium and testNG related jar files).
  • Add 2 more latest version jar files (these doesn’t come along with selenium), go to

https://mvnrepository.com/artifact/org.freemarker/freemarker

https://mvnrepository.com/artifact/org.mongodb/bson

NOTE: click on above links, select the latest version and then click on Download (JAR)

Let’s look into the code implementation

1st thing, we need a utility or base class (ExtentManager.java) that takes care all the extent configuration, so that test cases will be using this ExtentManager.java to generate report.





Create testcases, log results or steps to generate report

run the TC1.java, refresh your project, you will see extentreport.html created, open html page in a browser to see the extent report.

Explanation :

in ExtentManager.java, we are getting the objects of ExtentReports, ExtentHtmlReporter and ExtentTest , so separate test cases can use those objects to send test results to generate report.

each test case will have

  • @BeforeClass – get the ExtentReports object and some test case specific code statements.
  • @Test  – actual test case functionality.
  • @AfterClass – to write the test case results in to html (extent.flush())

All other code statements are explained with below screenshot

selenium-result-report-using-extent-report-version-3

Configuration :

Extent report can be customized or configured by using ExtentHtmlReporter.config() (e.g – setDocumentTitle, setReportName) or by using config.xml and load it at run time.

NOTE: In the above code implementation, we saw how to configure extent report using ExtentHtmlReporter.config()

Now let’s see how we can load and cofigure report using config.xml

a typical config.xml –

Do required changes to the config.xml and place under your project folder, and change the ExtentManager.java a bit to use the xml file.

 

References –

github – extent report in java

Extent report

https://github.com/anshooarora/extentreports-java/issues/652

Update –

Updated GetExtent() under class ExtentManager

if(extent != null)

return extent; \\to avoid creating new instance of html file at every test run

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

9 Responses

  1. Rahul Rana says:

    I have multiple class files with multiple methods in it. I need one report for the entire run but the all reports are overwritten and report for only last class is visible. I tried changing extent = new ExtentReports(); to extent = new ExtentReports(path, false); but its not allowing me to do it

  2. sunilpatro1985 says:

    Workaround to your problem –
    Download extentreports-3.0.1.jar and replace existing jars with this latest to the current project, and add htmlReporter.setAppendExisting(true); under the GetExtent() method.

    NOTE: make sure every time you execute tests, create an empty html file or else it will append even all your prev results.

  3. srikanth says:

    I took your source code to generate report. I just created the same ExtentManager.java

    I have my own test . when i execute I am not getting any error but the output is not generated.

    I am using extentreports 3.0.2. I am new to testng and extent reports.

    Could you please help me

  4. dsa127 says:

    Do you not have to use endTest(testName) anymore?

    • sunilpatro1985 says:

      Not required, extent.flush() will do that for you, are you getting any issues generating report with out endtest(testname)?

  5. mahi says:

    can we execute Jmeter script through this extent class and generate extent reports

  6. Diana says:

    Thank you sunilpatro1985 · , this was really helpful!
    But I have a problem with encoding. All my descriptions in cyrillic, last running test case is shown in report with cyrillic. But the other test which was run before shown like symbols (question marks).
    I change config xml cp1251 but it doesn’t help

  1. October 19, 2016

    […] For extent report version 3.x, please follow Selenium reporting using extent report ver 3.x […]

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: