Class ExtentReports

  • All Implemented Interfaces:
    AnalysisTypeConfigurable, Writable

    public class ExtentReports
    extends AbstractProcessor
    implements Writable, AnalysisTypeConfigurable

    The ExtentReports report client for starting reporters and building reports. For most applications, you should have one ExtentReports instance for the entire JVM.

    ExtentReports itself does not build any reports, but allows reporters to access information, which in turn create the reports. An example of building an HTML report and adding information to ExtentX:

     ExtentSparkReporter spark = new ExtentHtmlReporter("ExtentSpark.html");
     ExtentReports extent = new ExtentReports();
     extent.attachReporter(spark);
     
     extent.createTest("TestName").pass("Test Passed");
     
     extent.flush();
     

    A few notes:

    • It is mandatory to call the flush method to ensure information is written to the started reporters.
    • You can create standard and BDD-style tests using the createTest method
    See Also:
    ExtentTest, GherkinKeyword, IGherkinFormatterModel, Status
    • Constructor Detail

      • ExtentReports

        public ExtentReports()
    • Method Detail

      • attachReporter

        public void attachReporter​(ExtentObserver... observer)
        Attach a ExtentObserver reporter, allowing it to access all started tests, nodes and logs
        Parameters:
        observer - ExtentObserver reporter
      • createTest

        public ExtentTest createTest​(GherkinKeyword gherkinKeyword,
                                     String name,
                                     String description)
        Creates a BDD-style test with description using name of the Gherkin model such as:

        Example:

         extent.createTest(new GherkinKeyword("Feature"), "feature", "description");
         extent.createTest(new GherkinKeyword("Scenario"), "scenario", "description");
         extent.createTest(new GherkinKeyword("Given"), "given", "description");
         
        Parameters:
        gherkinKeyword - Name of the GherkinKeyword
        name - Name of test
        description - A short description of the test
        Returns:
        ExtentTest object
      • createTest

        public ExtentTest createTest​(GherkinKeyword gherkinKeyword,
                                     String testName)
        Creates a BDD-style test using name of the Gherkin model such as:

        Example:

         extent.createTest(new GherkinKeyword("Feature"), "feature");
         extent.createTest(new GherkinKeyword("Scenario"), "scenario");
         extent.createTest(new GherkinKeyword("Given"), "given");
         
        Parameters:
        gherkinKeyword - Name of the GherkinKeyword
        testName - Name of test
        Returns:
        ExtentTest object
      • createTest

        public ExtentTest createTest​(String name,
                                     String description)
        Creates a test with description
        Parameters:
        name - Name of test
        description - A short test description
        Returns:
        ExtentTest object
      • createTest

        public ExtentTest createTest​(String name)
        Creates a test
        Parameters:
        name - Name of test
        Returns:
        ExtentTest object
      • removeTest

        public void removeTest​(ExtentTest test)
        Removes a test
        Parameters:
        test - ExtentTest object
      • removeTest

        public void removeTest​(String name)
        Removes a test by name
        Parameters:
        name - The test name
      • flush

        public void flush()
        Writes test information from the started reporters to their output view
        • ExtentSparkReporter: flush output to HTML file
        • ExtentKlovReporter: inserts or updates info in MongoDB
        Specified by:
        flush in interface Writable
      • setSystemInfo

        public void setSystemInfo​(String k,
                                  String v)
        Adds any applicable system information to all started reporters

        Example:

         extent.setSystemInfo("HostName", "AventStack");
         
        Parameters:
        k - Name of system variable
        v - Value of system variable
      • addTestRunnerOutput

        public void addTestRunnerOutput​(List<String> log)
        Adds logs from test framework tools to the test-runner logs view (if available in the reporter)

        TestNG usage example:

         extent.setTestRunnerOutput(Reporter.getOutput());
         
        Parameters:
        log - Log string from the test runner frameworks such as TestNG or JUnit
      • addTestRunnerOutput

        public void addTestRunnerOutput​(String log)
        Adds logs from test framework tools to the test-runner logs view (if available in the reporter)

        TestNG usage example:

         for (String s : Reporter.getOutput()) {
             extent.setTestRunnerOutput(s);
         }
         
        Parameters:
        log - Log string from the test runner frameworks such as TestNG or JUnit
      • tryResolveMediaPath

        public ExtentReports tryResolveMediaPath​(String[] path)
        Tries to resolve a Media location if the supplied path is not found using supplied locations. This can resolve cases where the default path was supplied to be relative for a FileReporter. If the absolute path is not determined, the supplied will be used.
        Parameters:
        path - Dirs used to create absolute path of the Media object
        Returns:
        ExtentReports
      • createDomainFromJsonArchive

        public void createDomainFromJsonArchive​(File jsonFile)
                                         throws IOException
        Creates the internal models by consuming a JSON archive from a previous run session. This provides the same functionality as available in earlier versions via appendExisting, with the exception of being accessible by all reporters instead of just one.
        Parameters:
        jsonFile - The JSON archive file
        Throws:
        IOException - Exception thrown if the jsonFile is not found
      • createDomainFromJsonArchive

        public void createDomainFromJsonArchive​(String jsonFilePath)
                                         throws IOException
        Creates the internal models by consuming a JSON archive from a previous run session. This provides the same functionality as available in earlier versions via appendExisting, with the exception of being accessible by all reporters instead of just one.
        Parameters:
        jsonFilePath - The JSON archive file
        Throws:
        IOException - Exception thrown if the jsonFilePath is not found
      • setReportUsesManualConfiguration

        public void setReportUsesManualConfiguration​(boolean useManualConfig)
        Use this setting when building post-execution reports, such as from TestNG IReporter. This setting allows setting test with your own time-stamps. With this enabled, Extent does not use time-stamps for tests at the time they were created.

        If this setting is enabled and time-stamps are not specified explicitly, the time-stamps of test creation are used.

        Parameters:
        useManualConfig - Set to true if building reports at the end of execution with manual configuration
      • setAnalysisStrategy

        public void setAnalysisStrategy​(AnalysisStrategy strategy)
        Type of AnalysisStrategy for the reporter. Not all reporters support this setting.

        There are 2 types of strategies available:

        • TEST: Shows analysis at the test and step level
        • SUITE: Shows analysis at the suite, test and step level
        Specified by:
        setAnalysisStrategy in interface AnalysisTypeConfigurable
        Parameters:
        strategy - AnalysisStrategy determines the type of analysis (dashboard) created for the reporter. Not all reporters will support this setting.
      • keepLastRetryOnly

        public void keepLastRetryOnly​(boolean keepLastRetryOnly)
        This setting allows only 1 instance of a test or node to be present in the report. To maintain uniqueness, the name of the test is used.
        Parameters:
        keepLastRetryOnly - true - keeps only the last executed test instance
      • getStats

        public ReportStats getStats()
        Returns an instance of ReportStats with counts of tests executed by their status (pass, fail, skip etc)
        Returns:
        an instance of ReportStats
      • onAuthorAssigned

        protected void onAuthorAssigned​(Author x,
                                        Test test)
      • onCategoryAssigned

        protected void onCategoryAssigned​(Category x,
                                          Test test)
      • onDeviceAssigned

        protected void onDeviceAssigned​(Device x,
                                        Test test)