Generating HTML TestNG reports

后端 未结 4 1658
无人及你
无人及你 2020-12-12 04:27

I want to generate HTML testNG reports. By default we have a report file after running testNG called \"emailable-reports\". But now i want to create my own HTML report. I t

相关标签:
4条回答
  • 2020-12-12 04:58

    Per the documentation, implementations of the ITestListener interface are designed for real-time reporting, while implementations of the IReporter interface are intended to generate reports after the suite run is finished.

    Implementing an instance of IReporter and the generateReport(List<ISuite> suites, String outputDirectory) method should allow you to look at the test results and create an HTML report.

    0 讨论(0)
  • 2020-12-12 05:10

    I know this is an old thread, but I have explained here how to customize TestHTMLReporter and here it is:

    With your customReport You'd have to implement IReporter , extend TestListenerAdapter and override generateReport method if you want to implement a custom TestHTMLReporter . For other reporters you may have to do things a bit differently but the concept will remain the same. You'd achieve custom 'TestHTMLReporter' like below .

    Create a CustomReport.java file in your project and copy-paste the whole content of TestHTMLReporter.java , change the name of file in getOutputFile method and it would look like below

    public class CustomReport  extends TestListenerAdapter implements IReporter {
    
         @Override
            public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
                                       String outputDirectory) {
    
            }
       ...
       //paste the content of TestHTMLReporter.java here
       ...
       ...
    

    Make sure all your imports are in place from TestHTMLReporter.java Now, in this file change as per your requirement . For ex: if you'd like to add the end time of each of the test then at the correct place in generateTable method add the below snippet

    // Test class
          String testClass = tr.getTestClass().getName();
           long testMillis = tr.getEndMillis();
            String testMillisString = Long.toString(testMillis);
          if (testClass != null) {
            pw.append("<br>").append("Test class Name: ").append(testClass);
    
             // this line to add end time in ms
            pw.append("<br>").append("End Time(ms): ").append(testMillisString); 
            // Test name
            String testName = tr.getTestName();
            if (testName != null) {
              pw.append(" (").append(testName).append(")");
    
            }   
    

    Then you'll get like below

    Now, You'll get two reports one with default and the other with your file name. The only thing now remains is switching off the default reporting listeners, so you get only one report. For that you can follow this or you may search for solutions. Hope this helps

    0 讨论(0)
  • 2020-12-12 05:13

    @Feanor - As per your implementataion

    ################
      Implementing an instance of IReporter and the generateReport(List<ISuite> suites, String outputDirectory)
    #################
    

    We have a problem here. Assume we have implemented as instance of Ireporter say "CustomReporter" and override generateReport which gets called by adding listener in xml file

    After this testng will ALSO call EmailableReport which also implements Ireporter which reverts back to default testNg report

    0 讨论(0)
  • 2020-12-12 05:16

    you can use QAF with which you will be able to generate json based reporting dashboard.

    0 讨论(0)
提交回复
热议问题