Similar Posts

77 Comments

    1. Hi Satya, Result will be displayed based on @AfterMethod. I just took If and else if. You could mention another else if for pass condition. Result will be displayed based on the result of the test case.

    2. Hi Rajkumar,

      Can we append extra information like displaying some project variables which will be useful for analysis purpose, where user will go through report only instead of log file

      Regards,
      Shruti

  1. Hi Rajkumar,

    I have a task related to reporting in testng and need your help in deciding the approach. Basically we want to see in reports all the assertions that are used in a test method. In our present framework we do get the test result populating which all methods are passed/failed in a java class , in addition to it now we want to display the assertions(Pass or Fail) which are written inside those method in the HTML report.
    Many thanks in advance

  2. Hi Rajakumar,

    Thanks for the reply , I was also thinking the same to write some wrapper with logging around Testng assertions . Just wanted to check if any advance report like extent report generates details including assertion inside a particular methods in report layout. I am expecting output in below format, let me know if you need more information.

    Current Tests reults
    Duration Passed Skipped Failed Pass Rate
    Test Class 1 0.158s 2 0 0 100%
    Test Class 2 0.156s 1 0 0 100%
    Test class 3 0.598s 1 0 0 100%
    Total 4 0 0 100

    Expected Test result
    Test Class 1
    Method 1 Passed Skipped Failed
    Assert Equal-“validation name” 1 0 0
    Assert True-“Validation name 1 0 0
    Assert False-“Validation Name” 0 0 1

    Method2
    Assert Equal-“validation name”
    Assert True-“Validation name
    Assert False-“Validation Name”

    1. Hi Reetanshu, I have gone through extent report documentation to include assertions in the report but no luck. I guess, it’s better to move on with logs around assertions. Thanks.

      1. Hi Rajkumar, Its not possible. May be in the later version they may release this. By the way, how could i add screenshots in the extent reports.
        Thanks in advance Rajkumar.

          1. Hey Dear My TestNG Report is showing Broken UI, Not including inline css, am not using jenkins ,just creating simple project in TestNG and using Extent Report, plz help me

  3. Hi Rajkumar,

    When using extent reports with screenshots, I am seeing few places, screenshots are getting misplaced. So how can we avoid that?

    Any suggestions are welcome.

    1. Hi Naveen, Could you please give me more information. Misplaced means? You could place your screencapture method whereever you required. It may be due to synchronization issue. Place some waits to capture screenshot of the right page.

      1. Hi Raj,

        Misplaced in the sense – Expected page screenshot is displayed in other place. E.g Login screenshot appeared after the login successful in the reports. This supposed to be present in the login section

        This might be due to synchronization issue, let me add few more wait and will see how the results are getting generated.

        Thanks for your input.

  4. Do I need to implement this in every test cases? can’t it be modularize and invoke in each test cases. PLease reply soon

      1. do you mean as per your example “extendreportsclass” should be written within utility class and call whenevr needed? Sorry to bother you by such silly qs, but as I am very new in this automation domain, can you please share some code snippet for the same, it will be helpful.
        As of now, i have implemented multiple testcases with testng integration.

          1. Hi Ayan, Place these (@BeforeTest, @AfterMethod and @AfterTest of extent reports..) in your Base class and call (logger = extent.startTest(“your test name goes here”)) in your tests..
            if any test fails, @AfterMethod will be called and dispalys the message in the report.

  5. HI

    I want to use this in multiple test cases? do I need to implement this in all test cases separately? or there is a way to modularize the same and implement this by calling the methods.

  6. you can capture assert failure in Extent report as well. We have implemented in your project. try to use your code in try catch block and in catch block capture the fail status.

    for ex

    }
    catch (Throwable t) {

    test.log(LogStatus.FAIL, t);

    throw t;

    }

    }

    @After
    public void afterTest() throws Throwable {
    try{
    new NbnLoginPage().logout_maximo();
    new Page().ScreenshotToPDf(getClass().getSimpleName());
    endTest();
    }catch(Exception e)
    {
    System.out.println(“Some issue in closing test “);
    }
    }

  7. how to get bulk test results in one tab in extend report? like one tab in right side and one tab in left side and i want 10 test results?

  8. Hi, can you please tell me, how to generate a report for all tests which I have created via PageObject. I have a few test classes and pages. I have one functional/base page class, where I setup chrome driver and open a specific page, after that every test continue. Not start from the beggining. When I add your methods (@BeforeTest, @AfterMethod and @AfterTest) only to fuctional class, I got null pointer exception. Only when I add into every Test class every @annotation, test is runned. (I add also logger in the beggining of the tests, and status.passed in the end of the test, in both cases)

    And one more question, when I run through terminal all tests, with command mvn clean verify, I get report for only last Test class which has for e.g. 5 tests, nothing before that, ,even I have about 30 tests. Is possible to get report for all of them when they are runned on this way?

    Thank you very much

    1. Hi Sandra, Keep @BeforeTest, @AfterMethod, @AfterTest in your base class. Call this statement(logger = extent.startTest(“Your_Test_Case_Name”);) inside @Test method in your tests. If you still have any issues, pls let me know.

      1. Hi Rajkumar, when I leave that in the base class and not in the test class (and add only logger = extent.startTest(“Your_Test_Case_Name”);) inside @Test method), after run test fails in the beggining and I get this error:

        Test fail.

        Tests run: 3, Failures: 2, Errors: 0, Skipped: 1, Time elapsed: 18.52 sec <<< FAILURE! – in com.axonista.tests.AccountsTest
        checkRemocoVisibilityBetweenChannels
        (com.axonista.tests.AccountsTest) Time elapsed: 0.009 sec <<< FAILURE!
        java.lang.NullPointerException
        at com.axonista.tests.AccountsTest.
        checkRemocoVisibilityBetweenChannels(AccountsTest.java:89)

        generateReport(com.axonista.tests.AccountsTest) Time elapsed: 0.01 sec <<FuctionalTest.generateReport:97 » NullPointer

        can you please help me?

  9. Hi,

    Can u share any project you might have by chance which u made use of selenium using java for automating any web application?

    regards,
    ani

  10. Hi,
    I am facing this issues “Cannot instantiate the type ExtentReports”

    In this line “extent = new ExtentReports (System.getProperty(“user.dir”) +”/ExtentReport.html”, true);”
    it show’s this “Cannot instantiate the type ExtentReports” error.

  11. Hi
    I have fixed above issues.

    But i am not get the extent reports.

    here is code:
    “extent = new ExtentReports (System.getProperty(“user.dir”) +”/test-output/STMExtentReport.html”, true);”
    in test-output folder i am not able to see this “STMExtentReport.html” file.

  12. Hi!

    How can I add some dynamic data into this config?
    Say, I would like to have execution date in documentTitle tag .
    How should it look?

  13. Hello, did anyone ever try to upload their reports inside JIRA?

    Looks like JIRA does not allow html format.

    How do you guys upload your reports? Do you just email your reports?

    I would like to be able to upload my automation report inside JIRA ticket. Is it possible? Did anyone ever tried to upload their reports inside JIRA?

    Thank you in advanced.

  14. Hey Hi Raj – Great Article ..! Thanks for your time for this .

    Actually i followed same steps , but i struck on 2 things …

    Major one :

    When I’m running my scripts in a sequence I can able to run successfully & Im getting results too. When I’m running the same tests/methods/classes in parallel, all my Extent reports are getting messed up (one test logs are mixed into another test logs) and failing.For my tests, Im using Selenium with TestNG, Maven & Im running my tests in Sauce labs.

    Second one :

    I am calling Close() method in @AfterClass as i want to execute all my test but its throwing me the error close called before it self stating and all the tests are failing

    Can you please throw some light on this.

    Thanks ,Chaithanya

    1. Hi Chaithanya,
      I am struggling with the same issue. If you have found any solution then pls forward to me also.
      It will highly appreciated.

      Many thanks in advance.

  15. Hey Rajkumar,

    I am trying to figure out how can I insert multiple test reports into 1 mega report. So, this is how my testng.xml looks like:


    Currently I am flushing the report in @AfterSuite, but I am facing the problem when the tests (testng.xml test node) fail, @AfterSuite does not run and the report is not generated.

    I was thinking to flush reports in @AfterTest, and then put all test reports in 1 mega report. Is this doable?

    I want report to look something like: http://relevantcodes.com/Tools/ExtentReports2/ExtentMerge.html#

    I am using:
    Selenium Webdriver, TestNG, Java, Extent Report 2

    Thanks,
    Jigs

    1. Hi Jigs,

      Make it false in the below line of code and try it once.

      Mentioned in the blog.

      extent = new ExtentReports (System.getProperty("user.dir") +"/test-output/STMExtentReport.html", true);

      Modify it as below:

      extent = new ExtentReports (System.getProperty("user.dir") +"/test-output/STMExtentReport.html", false);

  16. Hi Raj Kumar,

    Very well explained. I was able to implement extent reports in my project successfully with the help of this tutorial. Great job. Awesome. Thank you very much!!!

  17. Hi

    Any idea about how to make Jenkins send the html file over the mail along with css and other dependencies ?

    How to enable Content Security Policy in Jenkins (installed in tomcat).

  18. How can i implement this Extent report in my project ? I tried and created the same “Testing material” package with all the above steps mentioned in my project. But whenever i run my project and refresh the project , the “STMExtentReport.html” under “test-output” shows the “Total tests run: 3, Failures: 1, Skips: 1” report (your project) and not my actual project report. What should i do so that my actual project test execution report gets reflect in “STMExtentReport.html”.

    1. Hi, refresh the project to see the report.
      What is the path you have given here
      extent = new ExtentReports (System.getProperty("user.dir") +"/test-output/STMExtentReport.html", true);
      Try to change the path and see.. Hope you know, you could create a new folder in your project. If you any other queries, please let me know.

      1. Hi Rajkumar, i tried with changing the path, but same results. I created the folder “Reports_Extent” under my project. Below is the path which i tried.
        extent = new ExtentReports (System.getProperty(“user.dir”) +”/Reports_Extent/STMExtentReport.html” ,true);

        appreciate your help Sir !!

  19. Hi Raj,

    I have implemented the extent reports in my sample projects with three classes.
    Running the testNG.xml file as TestNGSuite
    First class contains
    1. @Beforesuite and i have placed the extent part which you provided,
    2. @Test method to launch browser
    3. @AfterMethod and placed all the getresult method code
    4. @AfterSuite and added flush & close.
    Second class contains
    1..@Test method to fill one text box value
    Third class contains
    1..@Test method to fill the same text box value

    finally i am getting the reports as 1 Test passed and 2 Test failed with the below error for two times

    com.relevantcodes.extentreports.ExtentTestInterruptedException: Close was called before test could end safely using EndTest.
    at com.relevantcodes.extentreports.Report.terminate(Report.java:425)
    at com.relevantcodes.extentreports.ExtentReports.close(ExtentReports.java:915)
    at ngsuite.FirstClass.afterSuite(FirstClass.java:121)
    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.invokeConfigurations(Invoker.java:138)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:329)
    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:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

    Could you please help me to resolve the issue

        1. Hi Saravana,
          Do the following changes and try it again.
          1. @BeforeTest annotation to the method startReport
          2. @AfterTest annotation to the method endReport
          3. use this statement in the method launch
          logger = extent.startTest("Class 1");

          1. Hi Raj,
            Thank you for the inputs. Could you please provide me the update for the below query,

            1.. do i need to add @BeforeTest and @AfterTest instead of @Beforesuite&@Aftersuites.
            2. I have added logger=extent.startTest(“Class1”)

            Thank you in Advance

  20. Hi Raj,

    Thanks for wonderful video

    Reports are not generation for me, i am getting below warning

    WARNING: Unable to perform report configuration. The file C:\Users\aroy\workspace\CirtTrial\null\extent-config.xml was not found.

    Please help
    Thanks
    Abhijith

  21. Hii sir,
    Can u please help me in explaining how can i save folder to desktop which should contain all the test reports.How to generate folder to save report in computer

    Reply soon

    1. Execute the script and refresh the project. You can see the reports folder under your project like ‘test-output’. Right click on that go to properties to find the path.

  22. Hi Raj,

    (1) I implemented extent reports in my projects with multiple classes and several methods, is it possible to add the className at the beginning of the methods in a that class.

    (2) After building on jerkins and generate extent report, how can it auto send reports as email to different recipients?

    Thank you.
    Regards.

  23. hi,

    following error thrown after adding the code.

    java.lang.NoClassDefFoundError: freemarker/template/TemplateModelException
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:86)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:375)
    at ExtentReport.ExtentReportsClass.startReport(ExtentReportsClass.java:39)
    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:100)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:216)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:143)
    at org.testng.TestRunner.beforeRun(TestRunner.java:631)
    at org.testng.TestRunner.run(TestRunner.java:599)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
    at org.testng.SuiteRunner.run(SuiteRunner.java:270)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
    at org.testng.TestNG.runSuites(TestNG.java:1124)
    at org.testng.TestNG.run(TestNG.java:1096)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
    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)
    … 26 more

    1. Hi Rubin, Copy the exact code which I placed in this post and try to execute it. If it works, then modify your script as per your requirement.

    2. I am facing same error, I am using test ng to create test cases. I used two classes first one where we start the selenium webdirver under Before test method(where I put the above mentioned code just before the selenium code.)
      Second is test cases class where I put all test cases.
      Second class inherits first class. the project was working before using extent.

      please suggest.

      Thank you,
      Gaurav Arora

  24. Hi Rajkumar,

    can you help me out. I am getting Null pointer exception on

    extent = new ExtentReports (System.getProperty(“/Users/abilash_babu/Desktop/output/Reportfinal.html”),true);

    FAILED CONFIGURATION: @BeforeTest startReport
    java.lang.NullPointerException
    at java.base/java.io.File.(File.java:276)
    at com.relevantcodes.extentreports.Report.setFilePath(Report.java:523)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:78)
    at com.relevantcodes.extentreports.ExtentReports.(ExtentReports.java:373)
    at ExportTestPlan.TestReports.startReport(TestReports.java:31)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    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.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.beforeRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:616)
    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:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

    SKIPPED CONFIGURATION: @AfterMethod getResult
    SKIPPED CONFIGURATION: @AfterMethod getResult
    SKIPPED CONFIGURATION: @AfterMethod getResult
    SKIPPED CONFIGURATION: @AfterTest endReport
    SKIPPED: failTest
    SKIPPED: passTest
    SKIPPED: skipTest

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

    1. Hi Abilash, Error message says the file name you provided is null. Please check it out again. Copy the exact code which I placed in this post and try to execute it. If it works, then modify as per your requirement.

  25. Hi,

    I have downloaded and added the extent reports library to my project. but I am not able to import the extent report package when I am writing ExtentReports extentl;.

    hovering mouse over doesn’t showing any thing related to extent libraries.

    Please suggest

  26. hii guys.how to generate pdf file in selenium automation code.if you know please tell me guys

Leave a Reply

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