Selenium HTML result reporting using ExtentReports 2.X

selenium-reporting-using-extent-reportWhile 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,

1. Initial setup of ExtentReports
2. TestCase 1 (open browser, perform test, close browser)
3. TestCase 2 (open browser, perform test, close browser)

Class1

             —————————— Update: Extent version 2.40 on wards ———————————

Following code may not work

Now you can load config.xml file into the code, so manually change the xml file and load it at run time.

config.xml –

Syntax – let’s say config file name is – extent-config.xml

———————————————————————————————————–

Class2 : Testcase 1

Class3: TestCase2

Now create testNG.xml to run the above 2 test cases…

 

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.

Now click on the summary tab, to view the steps details

In details:

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

 

Above is to give some basic information about the report, (this is optional)

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 below link
http://extentreports.relevantcodes.com


 

For prior to 2.x versions of the ExtentReports details, follow

http://www.ontestautomation.com/creating-html-reports-for-your-selenium-tests-using-extentreports/
http://learn-automation.com/advance-selenium-reporting-with-screenshots/

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

22 Responses

  1. 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.

  2. fadi hussein says:

    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

  3. Gobinath says:

    ITs very useful thank you

  4. L V Prasad says:

    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

  5. sunilpatro1985 says:

    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..

  6. sangamesh says:

    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.

  7. sunilpatro1985 says:

    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

  8. Lawrence Ajay says:

    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

  9. Hanumant Sharma says:

    Hello,
    I am not able to get the Jar. The link mentioned is blank.

    Could you please provide the same.

    • Lawrence Ajay says:

      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

  10. Lawrence Ajay says:

    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

  11. Hanumant Sharma says:

    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.”);
    }

    • Lawrence Ajay says:

      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!

  12. Vinod says:

    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”);

  13. sunilpatro1985 says:

    Hi Vinod, which version of extent report you are using?

  14. aniket says:

    Is there any way to add bar graph in extent reports.

  15. very nice and precise information on using extent reports. thanks for this educative post.

  16. richa says:

    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?

  1. October 19, 2016

    […] 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 […]

Leave a Reply

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

%d bloggers like this: