Basic Selenium

Advance Selenium Reporting with Screenshots Part 2

This post is focusing on extent report version 2 but we have new version of extent report 3 and 4 which you can refer using below post.

Extent Report version 3 and 4

If you still want to use an older version then you can follow this post.

You can check the detailed description about extent report from here- Extent Report Documentation

I created a detailed Youtube video on this that will help you to achieve the same.

But before moving forward you should know some of the features that we are going to use in this video.

How to capture screenshot in Selenium

How to capture screenshot in failure only

 

Advance reporting Selenium with Screenshots

 

Download Extent report

1- Open http://extentreports.com/docs/versions/2/java/ and use maven dependency

<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version>
</dependency>

2- If you are not using maven then you can use jars directly but I would highly recommend you to use maven dependency.

 

Advance reporting Selenium

Now once you are done with above two Video’s now start implementing Version 2

 

 

 

 

Please refer the code which we discussed in above video

Advance reporting Selenium with Screenshots Part 2

package SmokeTest;

import library.Utility;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class VerifyTitle 
{

ExtentReports report;
ExtentTest logger; 
WebDriver driver;


@Test
public void verifyBlogTitle()
{
report=new ExtentReports("C:\\Report\\LearnAutomation.html");

logger=report.startTest("VerifyBlogTitle");

driver=new FirefoxDriver();

driver.manage().window().maximize();

logger.log(LogStatus.INFO, "Browser started ");

driver.get("https://vistasadprojects.com/mukeshotwani-blogs-v2");

logger.log(LogStatus.INFO, "Application is up and running");

String title=driver.getTitle();

Assert.assertTrue(title.contains("Google")); 

logger.log(LogStatus.PASS, "Title verified");
}


@AfterMethod
public void tearDown(ITestResult result)
{
if(result.getStatus()==ITestResult.FAILURE)
{

String screenshot_path=Utility.captureScreenshot(driver, result.getName());
String image= logger.addScreenCapture(screenshot_path);
logger.log(LogStatus.FAIL, "Title verification", image);


}

report.endTest(logger);
report.flush();

driver.get("C:\\Report\\LearnAutomation.html");
}


}

 

I have not written much for this post because already we have covered the same in past.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

142 thoughts on “Advance Selenium Reporting with Screenshots Part 2

  1. Niranjan says:

    Hi Mukesh,

    Is there any way we can provide more details related to test case in Extent report? Like I have a test case ID (in a test management tool) corresponding to test case I have automated which I need to display in automated test report…
    Please let me know more on this.

    1. Hi Niranjan,

      Yes, you can achieve it. You need to call desired API call provided by corresponding Test Management tool in order to fetch test case id while your test execution and use same id into ExtentTest logger or you have to pass it every time manually which is tiresome job.

  2. Amandeep Singh Sandhu says:

    Hi Mukesh
    We have implemented Keyword Driven Framework in our Product and is working fine. We want Extent Reports in our framework, is it possible to use Extent Reports in Keyword Driven Framework?

    1. Hi Amandeep,

      First of all, Extent reports API doesn’t depend upon any kind of framework. You can integrate it to your existing framework after adding it to project build path.

      1. Amandeep Singh Sandhu says:

        Thanks Mukesh for your reply!
        Extent Reports API integrated to framework. Is it compulsory to use TestNG for Extent Reports, as of now we are not using TestBG in our framework?

        1. Hi Amandeep,

          Extent Report APIs works without TestNG also.

          1. Amandeep Singh Sandhu says:

            Thanks Mukesh, I will try at my end. In case of any issue, I will ping for help again 🙂

          2. Sure Amandeep 🙂

      2. shaik says:

        Hi Mukesh
        I would like to leern ANT ,when you upload …..I’m waiting..

        1. Hi Shaik,

          I am planning for it and will upload soon.

  3. triveni reddy says:

    Hi Mukesh,

    Will extent reports provide consolidated report. like when I use selenium grid concept of hub to node1 and node2 execution consolidated reports in same html file ?

    1. Hi Triveni,

      Yes, extent report consolidate the test execution being executed in grid. Because you will be triggering execution from Hub not from node. So all report can be made available on hub machine.

  4. Dilip Kumar says:

    Hi Mukesh,
    I have multiple tests in different classes.when i execute testng.xml only the last test result is getting updated.
    What should i do to get the status of all the tests to get updated

    1. Hi Dilip,

      Are you telling about the result coming up in extent report ? Please make it clear.

    2. Sameer says:

      Hi Mukesh,

      I want to use extent report for my project, wherein I have used page object model approach and I want to show the screenshots that I have taken to verify the UI as well as the failed test cases screenshots in the extent report.

      And I want to generate extent report at the Suite level. Any idea about how to achieve this.

      1. Hi Sameer,

        You can achieve this in many ways, one way is that initialize report object in another class with @BeforeSuite method and extent this class to all your test classes so that same report object can be accessed by all your test methods.

  5. Nikhil Nerkar says:

    Hello, In your video, against the screenshot in report, I cannot see the text ‘Title verification’ which is mentioned in below line of code. In large frameworks we wont be able to make out which screenshot is for which failure.

    logger.log(LogStatus.FAIL, “Title verification”, image);

    1. Hi Nikhil,

      Extent report and logger don’t depend on WebDriver object. You can take the screenshot of page where your test case is getting fail. Other things you need to handle from your framework.

  6. Atul Vani says:

    Hi Mukesh, I followed all steps as you mentioned in video ” but on executing it throws NullPointerException. please help me to solve this problem.

    public class extentReport_Demo1 {

    public WebDriver driver;
    ExtentReports report;
    ExtentTest logger;

    @Test
    public void Launch_Browser(){

    report=new ExtentReports(“C:\\Extent Report\\Atulvani.html”);
    logger = report.startTest(“verifyGoogleTitle”);

    System.setProperty(“webdriver.chrome.driver”, “C:\\Appium Setup\\Browser Driver\\chromedriver.exe”);

    driver=new ChromeDriver();
    logger.log(LogStatus.INFO, “Browser is Launched”);

    driver.get(“http://google.co.in”);
    logger.log(LogStatus.INFO, “Application is Up and Running”);

    driver.manage().window().maximize();
    logger.log(LogStatus.INFO, “Browser is Maximized”);

    String title = driver.getTitle();
    System.out.println(“Title of the page is = “+title);
    logger.log(LogStatus.INFO, “Getting Title of the page successfully”);

    Assert.assertTrue(title.contains(“selenium”));
    logger.log(LogStatus.PASS, “Title is verified”);
    }

    @AfterMethod
    public void tearDown(ITestResult result){

    if(result.getStatus()==ITestResult.FAILURE)
    {
    String screenshot_path=Utility.captureScreenshot(driver, result.getName());
    String image = logger.addScreenCapture(screenshot_path);
    logger.log(LogStatus.FAIL, “Title verification”, image);
    }
    report.endTest(logger);
    report.flush();
    driver.get(“C:\\Extent Report\\Atulvani.html”);
    }
    }

    And For Utility Class….

    public class Utility {

    public static String captureScreenshot(WebDriver driver, String screenshotName){

    try {
    TakesScreenshot ts=(TakesScreenshot)driver;

    File source=ts.getScreenshotAs(OutputType.FILE);

    String dest = “C:\\Extent Report\\ScreenShots\\”+screenshotName+”.png”;

    File destination = new File(dest);

    FileUtils.copyFile(source, destination);

    System.out.println(“ScreenShot Taken”);

    return dest;

    } catch (Exception e) {

    System.out.println(“Exception while taking Screenshot”+e.getMessage());
    return e.getMessage();
    }
    }
    }

    1. Hi Atul,

      Please check this statement String screenshot_path=Utility.captureScreenshot(driver, result.getName())

  7. 37 says:

    Hi Mukesh,
    In my report the screenshot is not displayed. What should i do ?

    1. 37 says:

      It is working now. Thanks

      1. Hi there,

        Happy to hear it worked.

    2. Hi there,

      Kindly check the path of your report and path for screenshot files.

    3. Richa says:

      In my repot also screenshot not displayed

      1. Hi Richa,

        make sure you are using Java 8

  8. Asha says:

    how we can use extend reports in page object model framework

    1. Hi Asha,

      Yes, you can. Extend report doesn’t restrict itself to any particular framework.

  9. Nidhi Tripathi says:

    Hi Mukesh,

    Very nice tutorial. Tried implementing extent reports in my project but when using

    logger.log(LogStatus.PASS,”Element Clicked”,image_1);

    I’m just getting the screenshot not getting the message “Element CLicked along with it.

    1. is this Fixed Nidhi?

  10. Nidhi Tripahti says:

    Hi Mukesh,
    This is Nidhi , I want to use this extentreport API for the protractor framework. So is it possible to call this library using javascript as protractor uses javascripts for writing the scripts.

    1. Hi Nidhi,

      Extent report does not support Protractor framework as of now.

  11. satish says:

    Hi Mukesh,
    This is satish

    I am working with extent reports.Can i know we can change the report name dynamically which is saved in output folder.

    Ex:Can we add test cases status ie PASS/FAIL to report name after execution .

    Could you help me on this

    1. Yes Satish you can change the name at runtime based on timestamp or any other logic as well. We can add any status as well for test cases.

  12. Shobana says:

    Hi Mukesh,

    Thanks very much for the great tutorials, learning a lot. I pretty much followed your example to use extent reports, I keep getting this error. I used maven to download the jars, code is almost the same. I would appreciate some tips on how to solve this. Thanks again for your great service.

    1. is this fixed Shobana?

      1. Shobana says:

        No Mukesh, I retried it still doesn’t work, I can’t make out what is wrong. Any input would be appreciated

        1. Hope this is fixed now.

  13. Deb says:

    Hi Mukesh,

    Thanks for the detailed explanation.
    But I am getting a broken html report. Can you please suggest how can that be fixed.

    I have tried using extentreports-2.05.jar as well as extentreports-2.40.jar.

  14. Pulkit says:

    Hi Mukesh,

    I am not able to download the report from the given link as the link is not working. Did you update the link?

  15. Bhanu says:

    What are steps in report

    1. Steps in Automation is similar to Step is manual testing.

  16. Fion says:

    It works, thanks 🙂

  17. Ether says:

    Hi Mukesh,
    is this possible to launch the report automatically to the web browser after executing the test

  18. P H says:

    Hi Mukhesh ,
    Can you tell me which firefox version we can use for selenium webdriver java jar file 2.53?

  19. Raghavendra says:

    Hi Mukesh,
    Currently i am getting report for individual test cases, but i want to get the report for the entire suite, suppose if there are 20 testcases in suite, it should show the results for 20 testcases (Like 15 passed and 5 failed) and a corresponding graph which shows 15 passed and 5 failed, is there any way of doing this

    Thanks
    Raghavendra

  20. Ashutosh says:

    Hi Mukesh, Just want to know one thing if I have teste cases in diff class files and then i create one testng suite then how can i use this extent report concepts, when i try to use as per your blog, in that case only the report is shown with only cases from one class file. Could you please help here.

  21. akhil says:

    Hey, Mukesh.

    How can I use ExtentReports when I am running multiple classes using TestNG framework, Do I need to write the below code in all test classes.
    ExtentReports extent;
    ExtentTest logger;

    1. Hi Akhil,

      StartTest and EndTest you can call for every test and make sure flush method should come at last

      1. akhil says:

        Thanks alot Mukesh.
        So we no need to add Flush after method right.

  22. Devi sri says:

    Hi Mukesh,
    Your blog is really awesome. I’ve a doubt. I tried to attach extent report output as a .html file in mail. when i receive mail it’s missing all css. And i tried to convert .html to .pdf and nothing didn’t work. Is there any possiblility to attach the extent report output in mail

  23. Rahul says:

    After executing extent reports are displaying broken image. Can u help me with this

    1. Hi Rahul,

      The issue is the path of images is not correct so it will show broken icon. Kindly recheck the screenshot path.

  24. Ruth says:

    Hi Mukesh,

    Is it possible to use extent reports for batch execution. ?

    1. Hi Ruth,

      Yes we can do that but its tricky check below url for more details http://extentreports.relevantcodes.com/java/#parallel-runs

  25. Vadim Z. says:

    I’m unable to zoom screenshot, which was includes into report in Firefox, but working fine in Chrome.

    1. Seems extent report issue.Not sure on this.

  26. Rachana says:

    Hi Mukesh,

    Just wanted to know weather it is possible for us to add expected and actual result in the extent and report look quite impressive 🙂

    1. Yes you can add them in logger.log to get into HTML report.

  27. Anandhi says:

    Dear Mukesh,
    Thank you very much for the great tutorial. Would it be possible to share some information on how to configure ExtentReports in Jenkins CI?

    Best Regards,
    Anandhi

    1. Hi Anandhi,

      It is same like normal process no other changes in Jenkins.

  28. Yogiraj says:

    Hi Mukesh,

    in my selenium test project i’m using Page object model where i have different classes for each page and there is one testNG class which has all the test methods/cases. extent reporting works correctly within test methods but i want to add the logs in to same report file from the page classes as well when that particular method is called from testNG test methods.

    e.g. below is my testNG test method which calls login method

    @Test
    public void VerifyLoginSuccess() throws Exception {

    extent= new ExtentReports(“E:\\Report\\MyReport.html”);
    logger=extent.startTest(“VerifyLoginSuccess”);
    driver = new FirefoxDriver();
    LoginPage login = new LoginPage(driver);
    logger.log(LogStatus.INFO, “Browser started “);
    Dashboard dashboard = new Dashboard(driver);
    CommonFunctions cfunction = new CommonFunctions(driver);
    dashboard = login.LoginToHRM(“username”, “password”);
    String ActualText = dashboard.GetDashboardText();
    Assert.assertEquals(ActualText, “Dashboard”,”Successfully logged in”);
    cfunction.LogOut();
    logger.log(LogStatus.INFO, “Portal Log out “);

    }

    1. You forgot to call endTest and flush method

  29. Padmaj says:

    Hi Mukesh,

    Thank you so much for writing this blog and guiding us through automation using Selenium . The info and videos are really helpful even for a person who is new to automation.

    Hey I used the Extent Report in my case but getting error. So I copied your code and tried again but getting similar error. Could you please suggest if any changes are needed?

    Here is the error:
    FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifyBlogTitle status=FAILURE method=VerifyTitle.verifyBlogTitle()[pri:0, instance:advancedReport.VerifyTitle@c0edeb] output={null}])
    java.lang.NullPointerException
    at advancedReport.Utility.captureScreenshot(Utility.java:15)
    at advancedReport.VerifyTitle.tearDown(VerifyTitle.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:703)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

    FAILED: verifyBlogTitle
    java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:85)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:419)
    at advancedReport.VerifyTitle.verifyBlogTitle(VerifyTitle.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
    Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateModelException
    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)
    … 27 more

    ===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
    Configuration Failures: 1, Skips: 0

    1. Hi Padmaj,

      Thanks for nice feedback. I can see null pointer exception in Utility. Have you created this library for screenshot ? If not then first create this lib and then try once again.

  30. Yogiraj Ghumade says:

    Hi Mukesh,

    i am using extentreports in my sample test as shown in below code, the test is running without errors but it is not creating the html report file, though it creates only empty folder.
    what is missing here?

    Any help on this much appreciated.!!

    Thanks,
    Yogiraj

    public class MyTests {
    ExtentReports extent;
    ExtentTest logger;
    WebDriver driver;

    @Test
    public void VerifyLoginSuccess() throws Exception {

    extent= new ExtentReports(“E:\\Report\\MyReport.html”);
    logger=extent.startTest(“VerifyLoginSuccess”);
    driver = new FirefoxDriver();
    LoginPage login = new LoginPage(driver);
    logger.log(LogStatus.INFO, “Browser started “);
    Dashboard dashboard = new Dashboard(driver);
    CommonFunctions cfunction = new CommonFunctions(driver);
    dashboard = login.LoginToHRM(“username”, “password”);
    String ActualText = dashboard.GetDashboardText();
    Assert.assertEquals(ActualText, “Dashboard”,”Successfully logged in”);
    cfunction.LogOut();
    logger.log(LogStatus.INFO, “Portal Log out “);

    }

    @AfterTest
    public void afterTest() {

    extent.endTest(logger);
    driver.close();
    driver.quit();

    }
    }

    1. Hi Yogiraj,

      I got the issue. You missed to call flush method after endTest 🙂

      Kindly refer the post again and let me know if still issue persist.

      1. Yogiraj says:

        Thanks Mukesh, that solved the issue, Thanks again and keep up the good work

  31. Raghavendra Gupta says:

    Hi Mukesh- I am getting ExtentReports link which navigates to “http://extentreports.relevantcodes.com/” in the automation test report. How to avoid displaying this in my automation test report. I have searched different config but no luck. Could you please let me know how to hide that link in my test report. I am using the version 2.41.1

    1. Hi Raghavendra,

      You can only make these changes to report http://extentreports.relevantcodes.com/java/#configuration

  32. salwa samad says:

    Hey ,

    This is very informative . I really like your videos .

    I have a question hope you can help me with it.

    Extent reports are email-able reports so when you take a screenshot on failure and save it on your local machine how can you send the full report with the screenshot to someone by email i mean what if i want to send the extent report to someone in my team , they wont get the image on the failed testcase screen as its on my local .

    Can you please advise.

    Thanks
    Salwa

    1. Hi Salwa,

      In this case store all the screenshot in shared driver and then access and send email http://www.assertselenium.com/java/emailable-reports-for-selenium-scripts/

  33. Vishnu Godse says:

    Thanks a lot Mukesh… for introducing such wonderful method for advanced reporting.

    Found really helpful and on basis of this article , i have created combined report for multiple Test(s)
    just declared report interface as :

    private static ExtentReports report = new ExtentReports (“G:\\Selenium\\AdvancedReports\\MyReports.html”);;
    private static ExtentTest logger ;

    and started logger = report.startTest(“TC Name”)

    and ended report.endTest and Flush operation under @AfterClass Annotation.

    which worked successfully for me and very impressive combined report has been generated..

    Thanks A lot for this..Great Job!!

    1. Hey Vishnu,

      Cheers 🙂

      1. Venkatesh says:

        Awesome Mukesh.

        Your videos really help. And i prefer your stuff than any other information from GOOGLE.

        They are really good, informative, clear, interesting, to the point, in sync with up-comming requirements.

        Continue the good work, and share the knowledge with us.

        1. Hey Venkatesh,

          Thank you mate yes I will continue the same. Your comment related to Google has boosted my energy.

  34. Angira Sarkar says:

    Hi Mukesh
    I want to implement this reporting with Apache ANT Build.xml file, previously i used Report NG to generate the report now i want to use this Extent reports jar. Please tell me what modifications should i do to my Apache ANT build.xml. I use TestNG.xml to schedule tests.
    Thank u in advance

    1. Hey Angira,

      You can download jar and keep in lib folder where other files are located. Remaining process will be same.

      I will still suggest you to use maven rather then ant.

  35. Shantanu Shukla says:

    Hi Mukesh,

    I am getting below exception in my console upon trying to implement extent reports.

    Kindly suggest what shall i do to get rid of this exception:

    java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:85)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:374)
    at com.cgi.tests.reports.REG_TCT1001.beforeMethod(REG_TCT1001.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
    Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateModelException
    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)

    1. Hey Shantnu,

      Please download latest jars and add in project. It is due to some jar missing from extent report.

  36. Anusha says:

    [TestNG] Running:
    C:UsersAR2104AppDataLocalTemptestng-eclipse-1272743253testng-customsuite.xml

    screenshot taken
    FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifySeleniumBlog status=FAILURE method=ExtentReportsEx.verifySeleniumBlog()[pri:0, instance:appium.ExtentReportsEx@6a41eaa2] output={null}])
    java.lang.NullPointerException
    at appium.ExtentReportsEx.tearDown(ExtentReportsEx.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

    FAILED: verifySeleniumBlog
    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:470)
    at com.relevantcodes.extentreports.Report.(Report.java:607)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:72)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:373)
    at appium.ExtentReportsEx.verifySeleniumBlog(ExtentReportsEx.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
    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)
    … 52 more

    im getting the above error

    herre is my code
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.Assert;
    import org.testng.ITestResult;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;

    import com.relevantcodes.extentreports.ExtentReports;
    import com.relevantcodes.extentreports.ExtentTest;
    import com.relevantcodes.extentreports.LogStatus;

    import egs.trailblazer.baseutils.Constants;

    public class ExtentReportsEx {
    ExtentReports report;
    ExtentTest logger;
    WebDriver driver;

    @Test

    public void verifySeleniumBlog(){

    report=new ExtentReports(“F:\SeleniumWorkSpace\TrailBlazer\Reports\LearnAutomation.html”,true);

    logger=report.startTest(“verifySeleniumBlog”);

    driver=new FirefoxDriver();

    driver.manage().window().maximize();

    logger.log(LogStatus.INFO, “Browser started “);

    driver.get(“https://vistasadprojects.com/mukeshotwani-blogs-v2”);

    logger.log(LogStatus.INFO, “Application is up and running”);

    String title=driver.getTitle();

    Assert.assertTrue(title.contains(“Google”));

    logger.log(LogStatus.PASS, “Title verified”);

    }

    @BeforeMethod
    public void before(){

    }

    @AfterMethod
    public void tearDown(ITestResult result) throws IOException
    {
    if(result.getStatus()==ITestResult.FAILURE)
    {
    TakesScreenshot ts = (TakesScreenshot)driver;
    //File source = ts.getScreenshotAs(OutputType.FILE);

    String dest = Constants.screenshotFilePath+”\”+result.getName()+”__”+”.png”;
    File destination = new File(dest);
    //FileUtils.copyFile(source,destination);
    System.out.println(“screenshot taken”);
    String image= logger.addScreenCapture(dest);
    logger.log(LogStatus.FAIL,image, “Title verification”);

    report.flush();

    }

    }

    // driver.get(“..\Report\LearnAutomation.html”);
    }

    1. please add

      report.endTest(logger);

  37. santhosh says:

    Hi Mukesh,

    Am running one @Test method on multiple browser parallel using XML.
    now am saving results in different folder like chrome,mozilla

    is it possible to store/get result of the same @test case on diffrent browser using Extent reporting

    public ExtentReports report;
    public ExtentTest logger;

    @Parameters(“MyBrowser”)
    @Test
    public void IB(String MyBrowser) throws Exception{
    WebDriver driverThread=openBrowser(MyBrowser);
    report=Reporter(MyBrowser,report);
    logger=report.startTest(” test started”);
    }
    //——————–
    public ExtentReports Reporter(String MyBrowser,ExtentReports report){

    switch (MyBrowser) {

    case “Firefox”: case “F”: case “FF”: case “remote_firefox”:
    report=new ExtentReports(“HtmlOutput\\FireFox\\TC001.html”);
    return report;
    case “Chrome”: case “C”: case “remote_chrome”:
    report=new ExtentReports(“HtmlOutput\\chrome\\TC001.html”);
    return report;
    case “Internet Explorer”: case “IE”: case “remote_ie”:
    report=new ExtentReports(“HtmlOutput\\InternetExplorer\\TC001.html”);
    return report;
    case “Safari”: case “S”: case “remote_safari”:
    report=new ExtentReports(“HtmlOutput\\Safari\\TC001.html”);
    return report;
    default :
    return report;
    }
    }

    can you please tell me how to save results of same test cases on multiple browser using extent reporting

    Thank you in advance

    note:sorry my previous email Id was wrong

    1. you can use timestamp for this.

  38. Reema Shah says:

    Hi Mukesh,
    Thank you for the beautiful explanation.
    I used the same code for generating the report but it does not create the report in destination folder.
    Test scripts are executed and no errors are generated..
    Below is my code:
    package com.learnTestNG;

    import org.testng.annotations.Test;
    import static org.testng.Assert.*;
    import java.util.Iterator;
    import java.util.List;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.StaleElementReferenceException;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    /*import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;*/
    //import org.testng.annotations.Test;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;
    //import org.testng.annotations.Optional;
    //import com.beust.jcommander.Parameter;
    import com.relevantcodes.extentreports.ExtentReports;
    import com.relevantcodes.extentreports.ExtentTest;
    import com.relevantcodes.extentreports.LogStatus;

    public class TestRedBus
    {
    /*public static*/ static WebDriver driver;
    private static String baseUrl;
    ExtentReports report;
    static ExtentTest logger;
    private String filePath=”C:\\Script Report\\RedBusReport.html”;

    @BeforeTest
    public void beforeTest()
    {
    report=new ExtentReports(filePath);
    logger=report.startTest(“Verify Home page for RedBus.in”);
    driver = new FirefoxDriver();
    FirefoxProfile fxprofile=new FirefoxProfile();
    fxprofile.setAssumeUntrustedCertificateIssuer(true);
    fxprofile.setAcceptUntrustedCertificates(true);
    //driver.manage().window().maximize();
    logger.log(LogStatus.INFO, “Browser is up and running”);
    baseUrl= “https://www.redbus.in/”;
    driver.get(baseUrl);
    logger.log(LogStatus.INFO, “Application is up and running”);
    System.out.println(“Current URL is ” +driver.getCurrentUrl()) ;
    System.out.println(driver.getTitle());
    logger.log(LogStatus.INFO, “Got the title of application home page”);
    driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
    }

    @Test
    /*Enter source destination and
    * click on datepicker icon and then click on next button from calendar*/

    public void TestHomePage() throws InterruptedException
    {

    driver.findElement(By.id(“txtSource”)).sendKeys(“Mumbai”);
    driver.findElement(By.id(“txtDestination”)).sendKeys(“pune”);
    logger.log(LogStatus.INFO, “Entered Source and destination”);
    }
    @Test
    public static void testSelectOnwardDate() throws InterruptedException
    {
    System.out.println(“——————Staring with onward journey—————“);
    driver.findElement(By.id(“txtOnwardCalendar”)).click();
    driver.findElement(By.xpath(“.//*[@id=’rbcal_txtOnwardCalendar’]/table[2]/tbody/tr[1]/td[3]/button”)).click();
    Thread.sleep(3000);
    String date =”13-Jun 2016″;
    String splitter[]= date.split(“-“);
    System.out.println(splitter);
    String CheckInDay= splitter[0];
    String CheckInMonth_Year= splitter[1];
    System.out.println(CheckInDay);
    System.out.println(CheckInMonth_Year);

    //to get the month and year from Onward calendar
    List elements = driver.findElements(By.xpath(“.//div[@class=’Calendar’]/table/tbody/tr[@class=’monthHeader’]/td[@class=’monthTitle’]”));
    for (int i=0; i<elements.size(); i++)
    {
    System.out.println(elements.get(i).getText());
    if(elements.get(i).getText().equals(CheckInMonth_Year))
    {
    System.out.println("————————");
    //selecting the date

    List days = driver.findElements(By.xpath(“.//*[@id=’rbcal_txtOnwardCalendar’]/table[contains(@class ,’month’)][2]/tbody/tr/td[contains(@class, ‘day’)]”));
    for(WebElement d : days)
    {
    System.out.println(d.getText());
    if(d.getText().equals(CheckInDay))
    {
    d.click();
    Thread.sleep(3000);
    break;
    }
    }
    logger.log(LogStatus.INFO, “Selected onward journey date”);
    }
    }
    }

    @Test
    public static void testSelectReturnDate() throws InterruptedException
    {

    //Exception e= new Exception();
    System.out.println(“———-Staring function for return journey————–“);
    driver.findElement(By.id(“txtReturnCalendar”)).click();
    //driver.findElement(By.xpath(“.//*[@id=’rbcal_txtReturnCalendar’]/table[2]/tbody/tr[1]/td[3]/button”)).click();
    String Return_date =”14-Jun 2016″;
    String splitter_Date[]= Return_date.split(“-“);
    System.out.println(splitter_Date);
    String CheckOutDay= splitter_Date[0];
    String CheckOutMonth_Year= splitter_Date[1];
    System.out.println(CheckOutDay);
    System.out.println(CheckOutMonth_Year);
    try
    {
    //Selecting month and year from return calendar
    List elements = driver.findElements(By.xpath(“.//div[@id=’rbcal_txtReturnCalendar’]/table[contains(@class, ‘monthTable’)]/tbody/tr[@class=’monthHeader’]/td[@class=’monthTitle’]”));
    System.out.println(“—————Starting calculation for date/moth/year selection from calendar————-“);

    for(int j=0; j<elements.size(); j++)
    {
    System.out.println(elements.get(j).getText());

    Thread.sleep(3000);
    if(elements.get(j).getText().equals(CheckOutMonth_Year))
    {
    System.out.println("————————");
    //selecting the dates from return calendar

    List Returndays = driver.findElements (By.xpath(“.//*[@id=’rbcal_txtReturnCalendar’]/table[contains(@class ,’month’)][1]/tbody/tr/td[contains(@class, ‘day’)]”));
    for(WebElement d : Returndays)
    {
    System.out.println(d.getText());
    if(d.getText().equals(CheckOutDay))
    {
    d.click();
    Thread.sleep(3000);
    break;
    }
    }
    }
    }

    }
    catch(StaleElementReferenceException e)
    {
    e.printStackTrace();
    e.toString();
    System.out.println(“Trying to recover from Stale element ” +e.getMessage());
    }

    logger.log(LogStatus.INFO, “Selected return journey date”);
    driver.findElement(By.id(“searchBtn”)).click();
    logger.log(LogStatus.INFO, “Clicked on search buses”);
    System.out.println(driver.getTitle());
    logger.log(LogStatus.PASS, “Navigated to search buses page.”);
    }

    @AfterTest
    public void afterTest()
    {
    /* report.endTest(logger);
    report.flush();
    driver.close();
    driver.quit();*/
    //driver.get(“C:\\Script Report\\RedBusReport.html”);
    }

    }

    1. Hi,

      EndTest will generate report.

  39. Kumar says:

    Hi Mukesh,

    I followed all the steps exactly as you have mentioned in the video and downloaded the jar from http://mvnrepository.com/. But still I am getting below error when I run my tests.

    FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=tc1 status=FAILURE method=ReportTest.tc1()[pri:0, instance:testScripts.ReportTest@36b98809] output={null}])
    java.lang.NullPointerException
    at testScripts.ReportTest.tearDown(ReportTest.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:786)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

    FAILED: tc1
    java.lang.NoClassDefFoundError: freemarker/template/TemplateException
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
    at testScripts.ReportTest.tc1(ReportTest.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
    Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
    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)
    … 27 more

    ===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
    Configuration Failures: 1, Skips: 0
    ===============================================

    ++++++++++++++++++++++++++++++++++++++++++++++++
    this is my code

    package testScripts;

    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.*;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.Test;

    import com.relevantcodes.extentreports.ExtentReports;
    import com.relevantcodes.extentreports.ExtentTest;
    import com.relevantcodes.extentreports.LogStatus;

    public class ReportTest {

    ExtentReports report;
    ExtentTest extentre;
    WebDriver driver;

    @Test
    public void tc1()
    {
    report = new ExtentReports(“C:\\Report.html”);
    extentre = report.startTest(“Verify the title”);
    driver = new FirefoxDriver();
    driver.get(“http://www.google.com”);
    driver.manage().window().maximize();
    extentre.log(LogStatus.INFO, “Browser Launched”);
    driver.manage().timeouts().implicitlyWait(5000 ,TimeUnit.SECONDS);
    String name = driver.getTitle();
    Assert.assertTrue(name.contains(“Google”));
    extentre.log(LogStatus.PASS, “Title verified”);
    }

    @AfterMethod
    public void tearDown(ITestResult result)
    {
    if(result.getStatus()==ITestResult.SUCCESS)
    {
    extentre.log(LogStatus.INFO, “Inside Success”);
    }

    report.flush();
    report.close();

    //driver.get(“D:\\ExtentReport\\Report.html”);

    }
    }

    1. Hi Kumar,

      Make sure all four jars added as I mentioned the above post.

      Please end the test then only it will create report.

      Add below code

      report.endTest(logger);

      remove this code

      report.close();

      1. Nitin says:

        Hi Mukesh,

        Despite failing the TC, it is not able to upload screenshot on Extent Report Path [C:\\Reports\\Learn-Automation.html].

        It seems the code String image = logger.addScreenCapture(screenshot_path); does not work anymore and they may have modified the same or maybe am missing something.

        Please clarify.

        Thank you,
        Nitin

        1. Hi Nitin,

          Its working fine I just checked Cheers 🙂

        2. VikramShaRma says:

          hi Mukesh i added all jars show in snapshot then its working as expected.
          Thanks alot

          1. Hey Vikaram,

            Cheers for new report.

  40. Garima Verma says:

    Hi Mukesh,

    I am trying to use relative path for adding a screenshot in my report but not sure why its not working-

    Here is how i am adding taking a screenshot –

    public static String captureScreenshot(WebDriver driver, String screenshotName)
    {
    try {
    TakesScreenshot ts = (TakesScreenshot)driver;
    File source = ts.getScreenshotAs(OutputType.FILE);
    String destold = “./target/runscreenshots/”;
    String dest = destold + screenshotName + “.png”;
    File destination = new File(dest);
    FileUtils.copyFile(source,destination);
    System.out.println(“screenshot taken”);
    return dest;
    }
    catch (Exception e)
    {
    System.out.println(“Exception while taking a screensht” +e.getMessage());
    return e.getMessage();
    }
    }
    and here is how i am adding to report
    logger.log(LogStatus.PASS, methodname + ” Add Attempt Success“);
    String image = this.captureScreenshot(driver, methodname + “Success”);
    System.out.println(“After capture”);
    String image1 = logger.addScreenCapture(image);
    System.out.println(“after image 1″ +image1);
    logger.log(LogStatus.INFO, methodname + ” Screenshot: “, image1);
    System.out.println(“after log” +image1);
    report.flush();

    Absolute paths are working fine but not sure why screenshot does not get attached using relative path. Any help would be appreciate. Thanks!

    1. Hi Garima,

      Ideally relative path also should work I will try in my machine and will let u know.

      Have a nice weekend.

      1. kishore says:

        Am really after using your report but am also facing the same problem

        1. Thanks 🙂 what issue u r facing?

  41. Rahul says:

    Hi Mukesh,

    I want to add Extent report at listeners and logging level on my project such that test logging that i input at test scripts and listeners output both will be available after execution of the test suite. Basically i want to mix extent report at listeners and logging level simultaneously. Currently while trying to add testng is executing single method twice from logging and from extent report but I want that to execute single method only and both logging and result any exception comes in a single method.

    Please help.

    Cheers!!

    -Rahul

    1. Hi Rahul,

      Can you send me ur code so that I can check and modify accordingly as per requirements.

  42. Manu says:

    Hi How you have added import library.Utility in “Advanced Selenium Reporting with Screenshots Part 2”.
    Dow we need any separate jar file for this?

    Thanks

    1. HI Manu,

      We have created this Utility to read excel refer below link for more details https://www.youtube.com/watch?v=sbBdj4zIMqY

  43. muthu says:

    Hi Mukesh,

    i had written the below code,

    @Test
    public void highestFareTest() throws IOException {

    String Path = “F:\\MyProject\\redbus\\test-output\\Extent.html”;
    ExtentReports extent = new ExtentReports(Path);

    ExtentTest test=extent.startTest(testName);

    new homePage(driver).searchBus(td.getData());
    test.log(LogStatus.PASS, “Site launched”);

    extent.endTest(test);

    }

    problem is test is getting executed , but extent.html file is not generated in the given path.

    Am using 2.40 jar of extent report.

    1. PLease add flush method after endtest

  44. Subramanya Baliga says:

    Hi Mukesh,

    Subramanya here. Would like to know how to share this extent report with screenshot to clients ? I did go through your comments section and came across a solution to keep screenshots in shared folder. Is there any other alternative solution for this ?

    1. HI Subramanya,

      I would recommend shared folder only because we are also using the same approach.

  45. divman says:

    Hi, It is very useful to me and i implemented in my project. But in the report i am not seeing the screenshot picture taken. I used the same code from your blog. Could you please let me know what should i do?

    1. Hi Divman,

      Please make sure that screenshot path is absolute (exact path relative path wont work).

      Let me know if still not fixed.

  46. Angad says:

    Hello Mukesh,

    I am not able to fetch screenshot using the above code , in Extent Report html file a, i am getting blank page screenshot. Can you please guide where i am going wrong ?

    Here is my code :-

    public class Login_To_Force
    {

    ExtentReports extent;
    ExtentTest test;
    WebDriver driver;

    @BeforeTest
    public void base()
    {
    extent = ExtentManager.Instance();

    // extent = new ExtentReports(“./ExtentReport.html”, true);
    driver = new FirefoxDriver();
    driver.get(“https://test.salesforce.com/”);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    }

    @Test(priority=1)

    public void LogintoSalesForce() throws InterruptedException
    {

    ExcelUtils Exceldata = new ExcelUtils(“TestData-SF.xls”, “Login”);

    //Actions myaction = new Actions(driver);

    Login loginsalesforce = PageFactory.initElements(driver,Login.class);

    test = extent.startTest(“Login Page”, “Verify login to Sales Force”);

    loginsalesforce.enterUserName(Exceldata.getCell(3, 0));
    test.log(LogStatus.PASS,”Enter Username”);

    loginsalesforce.enterPassWord(Exceldata.getCell(3, 1));
    test.log(LogStatus.PASS, “Enter Password”);

    loginsalesforce.clickSignin();

    test.log(LogStatus.PASS, “Click on Sign in button”);

    }

    @AfterMethod

    public void sShot(ITestResult result)
    {
    if(result.getStatus()==ITestResult.SUCCESS)
    {

    String screenshot_path=ExtentManager.CaptureScreen(driver, result.getName());
    String image= test.addScreenCapture(screenshot_path);
    test.log(LogStatus.PASS, “XYZ”, image);
    }
    }

    @AfterClass
    public void tear()
    {
    extent.endTest(test);
    extent.flush();
    extent.close();
    driver.quit();
    }

    1. Change below line

      before
      test.log(LogStatus.PASS, “XYZ”, image);

      After

      test.log(LogStatus.PASS, image,“XYZ”);

  47. Loren says:

    It works !!! 😉
    Thank you very much for your help . *hug* ;-)))

    Cheers
    Loren

    1. Hey Loren,

      Great Cheers 🙂

  48. puneet jain says:

    Hi Mukesh,

    How will i used extent report in key word-driven frame work? .

    As in framework there are 3 or more step against each test cases. so will i implement this in such a way that each test case content it test steps in hierarchy way.

    below piece of code return the result for test cases parent0 only. not for parent 1 and parent 2.

    public static void main(String arg[])
    {
    ExtentReports extent=new ExtentReports(“./demo.html”);

    ExtentTest parent=null;

    for(int i=0;i<3;i++){

    parent = extent.startTest("Parent"+i);

    for(int j=i;i<3;i++){

    ExtentTest child1 = extent.startTest("Child 1");
    child1.log(LogStatus.INFO, "Info from method"+j);

    parent
    .appendChild(child1);

    }
    extent.endTest(parent);
    extent.flush();

    }
    }

    Please have a look.

    Thank,
    Puneet Jain

  49. Loren Lai says:

    Hello,

    it seems that my last comment is deleted. 🙁
    Anyway, maybe I can ask once again.

    Question: How can I use only ONE “myReport.html” for two TestClassess ?
    E.g. I have two test classes, which I will execute via testng.xml …

    How should I configure the path to the myReport.html in my test class ?

    public class TestClass1() {

    @Test
    public void verifyBlogTitle() {
    report=new ExtentReports(“C:\\Report\\myReport.html”);
    ….
    }
    }

    public class TestClass2() {

    @Test
    public void verifyBlogTitle() {
    report=new ExtentReports(“C:\\Report\\myReport.html”);
    ….
    }
    }

    Thank you in advance.

    Cheers
    Loren

  50. Loren Lai says:

    Hello Mukesh,

    great tutorial and example 😉 Thank you for that.
    I have two questions, please:

    1) When I execute the 2 classes in testng.xml, e.g.

    My report is generate but it shows only test results from MyTestExample2 .

    Question: How to get only 1 myReport.html for 2 running MyTestExample1 & MyTestExample2 ?

    ————————————————————————–
    public class MyTestExample1 () {

    ExtentReports report = new ExtentReports(“C:\\\\Report\\myReport.html”);
    ExtentTest logger;

    @Test
    public void tc1() {}

    @Test
    public void tc2() {}


    }

    public class MyTestExample2 () {

    ExtentReports report = new ExtentReports(“C:\\\\Report\\myReport.html”);
    ExtentTest logger;

    @Test
    public void tc1() {}

    @Test
    public void tc2() {}


    }

    2) Currently when I execute the test in eclipse I get this warning or error in console

    Jan 14, 2016 4:02:04 PM com.relevantcodes.extentreports.Configuration
    INFORMATION: Configurating report from file:/C:/MyEclipseIDEForJavaDev/MYARCHIVES/extentreports-2.40.0/extentreports-java-2.40.0.jar!/com/relevantcodes/extentreports/resources/extent-config.xml

    Question: What does it mean and how can I solve it, please?

    Thank you for your help in advance.

    Cheers
    Loren

    1. Hi Loren,

      This is just some warning which is giving some information about template.

      I have sent a link in last comment please check and try the same.

  51. sonam says:

    hi manish i am getting below mentioned error while executing the same code
    com.relevantcodes.extentreports.Configuration
    INFO: Configurating report from file:/D:/selenium/extentreports-java-v2.40%20(1)/extentreports-2.40.0/extentreports-java-2.40.0.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
    FAILED CONFIGURATION: @AfterMethod teardown([TestResult name=verifytitle status=FAILURE method=ExtentReport.verifytitle()[pri:0, instance:ExtentReport@18aecf1] output={null}])

    please let me know the solution to come oot from this error. I have used 2.40 latest version

    1. Hi Sonam,

      Actually it known issue please download all jars from below link and add into project.

      Try again and let me know if still issue exist.

      In this video, we will use extent version 2 and will create advanced Selenium reporting with screenshot adding on failure.

      Download Jars from below location

      http://relevantcodes.com/wp-content/plugins/download-monitor/download.php?id=17

  52. sree says:

    Hi Mukesh,

    I followed all the steps exactly as you have mentioned in the video. But I am getting below error when I run my tests.

    Dec 22, 2015 9:28:50 AM com.relevantcodes.extentreports.Configuration
    INFO: Configurating report from file:/C:/Users/skara1/Desktop/lib/extentreports-2.40.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
    FAILED CONFIGURATION: @BeforeMethod init
    java.lang.NoClassDefFoundError: freemarker/template/TemplateException
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
    at SmokeTest.SampleTests.init(SampleTests.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    1. Hi Sree,

      is it fixed now ?

      1. Jessy says:

        Great tutorial but I am getting the error as shown below.

        [TestNG] Running:
        /private/var/folders/nf/yn_rmw7n0_5b08g50whn4jw80000gn/T/testng-eclipse-1248709115/testng-customsuite.xml

        Dec 24, 2015 7:19:50 PM com.relevantcodes.extentreports.Configuration
        INFO: Configurating report from file:/Users/Xavier/Documents/workspace/extentreports-2.40.jar!/com/relevantcodes/extentreports/resources/extent-config.xml
        Expection while taking a screenshotnull
        FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=verifyTitle status=FAILURE method=VerifyTitle.verifyTitle()[pri:0, instance:SmokeTest.VerifyTitle@6b71769e] output={null}])
        java.lang.NullPointerException
        at SmokeTest.VerifyTitle.tearDown(VerifyTitle.java:128)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:708)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:773)
        at org.testng.TestRunner.run(TestRunner.java:623)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
        at org.testng.SuiteRunner.run(SuiteRunner.java:259)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
        at org.testng.TestNG.run(TestNG.java:1018)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

        FAILED: verifyTitle
        java.lang.NoClassDefFoundError: freemarker/template/TemplateException
        at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:84)
        at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:230)
        at SmokeTest.VerifyTitle.verifyTitle(VerifyTitle.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:773)
        at org.testng.TestRunner.run(TestRunner.java:623)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
        at org.testng.SuiteRunner.run(SuiteRunner.java:259)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
        at org.testng.TestNG.run(TestNG.java:1018)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
        Caused by: java.lang.ClassNotFoundException: freemarker.template.TemplateException
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        … 27 more

        ===============================================
        Default test
        Tests run: 1, Failures: 1, Skips: 0
        Configuration Failures: 1, Skips: 0
        ===============================================

        =============================================

        1. Hi Jessy,

          I have noticed the same issue if you will download jar then it issue will come.

          Option 1- Download below jars to support extent report.

          Please find the attachment and download jar from maven repo http://mvnrepository.com/

          Option 2- Use Maven project and use below dependency in POM.xml


          com.relevantcodes
          extentreports
          2.40

          Thanks
          Mukesh

      2. Jessy says:

        Hi Mukesh

        I have to say that I had extentreports-2.40.jar already added to the project. I changed it to extentreports-2.05.jar and now it works.
        This tutorial would not work with the new version.

        Regards,
        Jessy

      3. Jessy says:

        And option two works fine for Maven project.

  53. shah says:

    my test didn’t work,although i follow your instruction precisely

    1. Have you gone through video 1 and video 2 ?

  54. shah says:

    Hi,Mukesh!I did exactly as you did but my program is not runniing it just showing an error

    1. Hi Shah,

      What error is coming?

  55. Jeevan Apte says:

    how to send this report to client?

    1. Hi Jeevan,

      First of all sorry for late reply. You can send this report without CSS. Screenshot will not be visible because location will change.

      You can store all screenshot to a separate shared folder where everyone have access and make the changes in screenshot path.

      Thanks
      Mukesh

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.