com.aventstack.extentreports

## Class ExtentReports

- java.lang.Object
- - com.aventstack.extentreports.ExtentReports

- All Implemented Interfaces:
    ReportService

      public class ExtentReports
      extends Object

  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 build the said reports. An example of building an HTML report and adding information to ExtentX:

       ExtentHtmlReporter html = new ExtentHtmlReporter("Extent.html");
       ExtentXReporter extentx = new ExtentXReporter("localhost");

       ExtentReports extent = new ExtentReports();
       extent.attachReporter(html, extentx);

       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 Summary

    Constructors
    Constructor and Description
    `ExtentReports()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `attachReporter(ExtentReporter... reporter)` Attach a `ExtentReporter` reporter, allowing it to access all started tests, nodes and logs
    `ReportConfigurator` | `config()` Provides common report configurations
    `ExtentTest` | `createTest(Class<? extends IGherkinFormatterModel> type, String testName)` Creates a BDD-style test representing one of the `IGherkinFormatterModel` classes such as: `Feature` `Background` `Scenario` `Given` `When` `Then` `And` `But`
    `ExtentTest` | `createTest(Class<? extends IGherkinFormatterModel> type, String testName, String description)` Creates a BDD-style test with description representing one of the `IGherkinFormatterModel` classes such as: `Feature` `Background` `Scenario` `Given` `When` `Then` `And` `But`
    `ExtentTest` | `createTest(GherkinKeyword gherkinKeyword, String testName)` Creates a BDD-style test using name of the Gherkin model such as: `Feature` `Background` `Scenario` `Given` `When` `Then` `And` `But`
    `ExtentTest` | `createTest(GherkinKeyword gherkinKeyword, String testName, String description)` Creates a BDD-style test with description using name of the Gherkin model such as: `Feature` `Background` `Scenario` `Given` `When` `Then` `And` `But`
    `ExtentTest` | `createTest(String testName)` Creates a test
    `ExtentTest` | `createTest(String testName, String description)` Creates a test with description
    `protected void` | `deregister(ExtentReporter reporter)` Unsubscribe the reporter.
    `protected void` | `end()` Ends logging, stops and clears the list of reporters
    `void` | `flush()` Writes test information from the started reporters to their output view extent-html-formatter: flush output to HTML file extent-klov-reporter: updates MongoDB collections extent-email-formatter (pro-only): creates or appends to an HTML file ConsoleLogger: no action taken
    `protected boolean` | `getAllowManualConfig()` Returns the current value of using manual configuration for test time-stamps
    `protected TestAttributeTestContextProvider<Author>` | `getAuthorContextInfo()` Returns the context of author with the list of tests for each
    `protected List<ExtentReporter>` | `getReporterCollection()` Retrieve a list of all started reporters
    `List<ExtentReporter>` | `getStartedReporters()` Returns a list of started reporters
    `ReportStatusStats` | `getStats()` Returns an instance of `ReportStatusStats` with counts of tests executed by their status (pass, fail, skip etc)
    `protected void` | `register(ExtentReporter reporter)` Subscribe the reporter to receive updates when making calls to the API
    `void` | `removeTest(ExtentTest test)` Removes a test
    `protected void` | `removeTest(Test test)` Removes the test and notifies all started reporters
    `protected void` | `saveTest(Test test)` Saves the started test and notifies all started reporters
    `protected void` | `setAllowManualConfig(boolean useManualConfig)` Setting to allow user driven configuration for test time-stamps
    `void` | `setAnalysisStrategy(AnalysisStrategy strategy)` Type of AnalysisStrategy for the reporter.
    `void` | `setGherkinDialect(String language)` Allows setting the target language for Gherkin keywords.
    `void` | `setReportUsesManualConfiguration(boolean useManualConfig)` Use this setting when building post-execution reports, such as from TestNG IReporter.
    `void` | `setSystemInfo(String k, String v)` Adds any applicable system information to all started reporters
    `protected void` | `setSystemInfo(SystemAttribute sa)` Add a system attribute
    `protected void` | `setTestRunnerLogs(String log)` Add a test runner log
    `void` | `setTestRunnerOutput(List<String> log)` Adds logs from test framework tools to the test-runner logs view (if available in the reporter)
    `void` | `setTestRunnerOutput(String log)` Adds logs from test framework tools to the test-runner logs view (if available in the reporter)

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExtentReports

          public ExtentReports()

  - ### Method Detail

    - #### attachReporter

          public void attachReporter(ExtentReporter... reporter)

      Attach a `ExtentReporter` reporter, allowing it to access all started tests, nodes and logs

      Available reporter types are:

      - ExtentHtmlReporter provided by artifactId "extent-html-formatter"
      - ExtentEmailReporter (pro-only) provided by artifactId "extent-email-formatter"
      - KlovReporter provided by artifactId "extent-klov-reporter"
      - ConsoleLogger
      Parameters:
        `reporter` - `ExtentReporter` reporter

    - #### getStartedReporters

          public List<ExtentReporter> getStartedReporters()

      Returns a list of started reporters
      Returns:
        A list of `ExtentReporter`

    - #### createTest

          public ExtentTest createTest(Class<? extends IGherkinFormatterModel> type,
                                       String testName,
                                       String description)

      Creates a BDD-style test with description representing one of the `IGherkinFormatterModel` classes such as:
      - `Feature`
      - `Background`
      - `Scenario`
      - `Given`
      - `When`
      - `Then`
      - `And`
      - `But`

      Example:

           extent.createTest(Feature.class, "feature", "description");
           extent.createTest(Scenario.class, "scenario", "description");
           extent.createTest(Given.class, "given", "description");

      Parameters:
        `type` - A `IGherkinFormatterModel` type
        `testName` - Name of test
        `description` - A short description of the test
      Returns:
        `ExtentTest` object

    - #### createTest

          public ExtentTest createTest(Class<? extends IGherkinFormatterModel> type,
                                       String testName)

      Creates a BDD-style test representing one of the `IGherkinFormatterModel` classes such as:
      - `Feature`
      - `Background`
      - `Scenario`
      - `Given`
      - `When`
      - `Then`
      - `And`
      - `But`

      Example:

           extent.createTest(Feature.class, "feature");
           extent.createTest(Scenario.class, "scenario");
           extent.createTest(Given.class, "given");

      Parameters:
        `type` - A `IGherkinFormatterModel` type
        `testName` - Name of test
      Returns:
        `ExtentTest` object

    - #### createTest

          public ExtentTest createTest(GherkinKeyword gherkinKeyword,
                                       String testName,
                                       String description)

      Creates a BDD-style test with description using name of the Gherkin model such as:
      - `Feature`
      - `Background`
      - `Scenario`
      - `Given`
      - `When`
      - `Then`
      - `And`
      - `But`

      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`
        `testName` - 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:
      - `Feature`
      - `Background`
      - `Scenario`
      - `Given`
      - `When`
      - `Then`
      - `And`
      - `But`

      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 testName,
                                       String description)

      Creates a test with description
      Parameters:
        `testName` - Name of test
        `description` - A short test description
      Returns:
        `ExtentTest` object

    - #### createTest

          public ExtentTest createTest(String testName)

      Creates a test
      Parameters:
        `testName` - Name of test
      Returns:
        `ExtentTest` object

    - #### removeTest

          public void removeTest(ExtentTest test)

      Removes a test
      Parameters:
        `test` - `ExtentTest` object

    - #### flush

          public void flush()

      Writes test information from the started reporters to their output view
      - extent-html-formatter: flush output to HTML file
      - extent-klov-reporter: updates MongoDB collections
      - extent-email-formatter (pro-only): creates or appends to an HTML file
      - ConsoleLogger: no action taken

    - #### setSystemInfo

          public void setSystemInfo(String k,
                                    String v)

      Adds any applicable system information to all started reporters

      Example:

           extent.setSystemInfo("HostName", "AventStack-PC");

      Parameters:
        `k` - Name of system variable
        `v` - Value of system variable

    - #### setTestRunnerOutput

          public void setTestRunnerOutput(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

    - #### setTestRunnerOutput

          public void setTestRunnerOutput(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

    - #### 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
      Parameters:
        `strategy` - `AnalysisStrategy` determines the type of analysis (dashboard) created for the reporter. Not all reporters will support this setting.

    - #### config

          public ReportConfigurator config()

      Provides common report configurations
      Returns:
        an instance of `ReportConfigurator`

    - #### setGherkinDialect

          public void setGherkinDialect(String language)
                                 throws UnsupportedEncodingException

      Allows setting the target language for Gherkin keywords.

      Default setting is "en"

      Parameters:
        `language` - A valid dialect from gherkin-languages.json
      Throws:
        `UnsupportedEncodingException` - Thrown if the language is one of the supported language from gherkin-languages.json

    - #### getStats

          public ReportStatusStats getStats()

      Returns an instance of `ReportStatusStats` with counts of tests executed by their status (pass, fail, skip etc)
      Returns:
        an instance of `ReportStatusStats`

    - #### register

          protected void register(ExtentReporter reporter)

      Subscribe the reporter to receive updates when making calls to the API
      Parameters:
        `reporter` - `ExtentReporter` reporter

    - #### deregister

          protected void deregister(ExtentReporter reporter)

      Unsubscribe the reporter. Calling unsubscribe will call the `stop` method and also remove the reporter from the list of started reporters
      Parameters:
        `reporter` - `ExtentReporter` reporter to unsubscribe

    - #### getReporterCollection

          protected List<ExtentReporter> getReporterCollection()

      Retrieve a list of all started reporters
      Returns:
        a list of `ExtentReporter` objects

    - #### saveTest

          protected void saveTest(Test test)

      Saves the started test and notifies all started reporters
      Parameters:
        `test` - a `Test` object

    - #### removeTest

          protected void removeTest(Test test)

      Removes the test and notifies all started reporters
      Parameters:
        `test` - a `Test` object

    - #### getAuthorContextInfo

          protected TestAttributeTestContextProvider<Author> getAuthorContextInfo()

      Returns the context of author with the list of tests for each
      Returns:
        a `TestAttributeTestContextProvider` object

    - #### end

          protected void end()

      Ends logging, stops and clears the list of reporters

    - #### setSystemInfo

          protected void setSystemInfo(SystemAttribute sa)

      Add a system attribute
      Parameters:
        `sa` - a `SystemAttribute` object

    - #### setTestRunnerLogs

          protected void setTestRunnerLogs(String log)

      Add a test runner log
      Parameters:
        `log` - a log event

    - #### setAllowManualConfig

          protected void setAllowManualConfig(boolean useManualConfig)

      Setting to allow user driven configuration for test time-stamps
      Parameters:
        `useManualConfig` - setting for manual configuration

    - #### getAllowManualConfig

          protected boolean getAllowManualConfig()

      Returns the current value of using manual configuration for test time-stamps
      Returns:
        setting for manual configuration

Copyright © 2018. All rights reserved.