Package com.aventstack.extentreports
Class ExtentReports
java.lang.Object
com.aventstack.extentreports.AbstractProcessor
com.aventstack.extentreports.ExtentReports
- All Implemented Interfaces:
AnalysisTypeConfigurable,Writable
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
flushmethod to ensure information is written to the started reporters. - You can create standard and BDD-style tests using the
createTestmethod
- See Also:
-
Field Summary
Fields inherited from class com.aventstack.extentreports.AbstractProcessor
keepLastRetryOnly -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds logs from test framework tools to the test-runner logs view (if available in the reporter)voidaddTestRunnerOutput(List<String> log) Adds logs from test framework tools to the test-runner logs view (if available in the reporter)voidattachReporter(ExtentObserver... observer) Attach aExtentObserverreporter, allowing it to access all started tests, nodes and logsvoidcreateDomainFromJsonArchive(File jsonFile) Creates the internal models by consuming a JSON archive from a previous run session.voidcreateDomainFromJsonArchive(String jsonFilePath) Creates the internal models by consuming a JSON archive from a previous run session.createTest(GherkinKeyword gherkinKeyword, String testName) createTest(GherkinKeyword gherkinKeyword, String name, String description) createTest(Class<? extends IGherkinFormatterModel> type, String name) Creates a BDD-style test representing one of theIGherkinFormatterModelclasses such as:FeatureBackgroundScenarioGivenWhenThenAndButcreateTest(Class<? extends IGherkinFormatterModel> type, String name, String description) Creates a BDD-style test with description representing one of theIGherkinFormatterModelclasses such as:FeatureBackgroundScenarioGivenWhenThenAndButcreateTest(String name) Creates a testcreateTest(String name, String description) Creates a test with descriptionvoidflush()Writes test information from the started reporters to their output view ExtentSparkReporter: flush output to HTML file ExtentKlovReporter: inserts or updates info in MongoDBgetStats()Returns an instance ofReportStatswith counts of tests executed by their status (pass, fail, skip etc)voidkeepLastRetryOnly(boolean keepLastRetryOnly) This setting allows only 1 instance of a test or node to be present in the report.protected voidonAuthorAssigned(Author x, Test test) protected voidonCategoryAssigned(Category x, Test test) protected voidonDeviceAssigned(Device x, Test test) voidremoveTest(ExtentTest test) Removes a testvoidremoveTest(String name) Removes a test by namevoidsetAnalysisStrategy(AnalysisStrategy strategy) Type of AnalysisStrategy for the reporter.voidsetGherkinDialect(String language) Allows setting the target language for Gherkin keywords.voidsetReportUsesManualConfiguration(boolean useManualConfig) Use this setting when building post-execution reports, such as from TestNG IReporter.voidsetSystemInfo(String k, String v) Adds any applicable system information to all started reporterstryResolveMediaPath(String[] path) Tries to resolve aMedialocation if the supplied path is not found using supplied locations.Methods inherited from class com.aventstack.extentreports.AbstractProcessor
convertRawEntities, onAuthorAdded, onCategoryAdded, onDeviceAdded, onFlush, onLogCreated, onMediaAdded, onMediaAdded, onNodeCreated, onReportLogAdded, onSystemInfoAdded, onTestCreated, onTestRemoved
-
Constructor Details
-
ExtentReports
public ExtentReports()
-
-
Method Details
-
attachReporter
Attach aExtentObserverreporter, allowing it to access all started tests, nodes and logs- Parameters:
observer-ExtentObserverreporter
-
createTest
public ExtentTest createTest(Class<? extends IGherkinFormatterModel> type, String name, String description) Creates a BDD-style test with description representing one of theIGherkinFormatterModelclasses such as:Example:
extent.createTest(Feature.class, "feature", "description"); extent.createTest(Scenario.class, "scenario", "description"); extent.createTest(Given.class, "given", "description");
- Parameters:
type- AIGherkinFormatterModeltypename- Name of testdescription- A short description of the test- Returns:
ExtentTestobject
-
createTest
Creates a BDD-style test representing one of theIGherkinFormatterModelclasses such as:Example:
extent.createTest(Feature.class, "feature"); extent.createTest(Scenario.class, "scenario"); extent.createTest(Given.class, "given");
- Parameters:
type- AIGherkinFormatterModeltypename- Name of test- Returns:
ExtentTestobject
-
createTest
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 theGherkinKeywordname- Name of testdescription- A short description of the test- Returns:
ExtentTestobject
-
createTest
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 theGherkinKeywordtestName- Name of test- Returns:
ExtentTestobject
-
createTest
Creates a test with description- Parameters:
name- Name of testdescription- A short test description- Returns:
ExtentTestobject
-
createTest
Creates a test- Parameters:
name- Name of test- Returns:
ExtentTestobject
-
removeTest
Removes a test- Parameters:
test-ExtentTestobject
-
removeTest
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
-
setSystemInfo
Adds any applicable system information to all started reportersExample:
extent.setSystemInfo("HostName", "AventStack");- Parameters:
k- Name of system variablev- Value of system variable
-
addTestRunnerOutput
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
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
Tries to resolve aMedialocation 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 theMediaobject- Returns:
ExtentReports
-
createDomainFromJsonArchive
Creates the internal models by consuming a JSON archive from a previous run session. This provides the same functionality as available in earlier versions viaappendExisting, 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
Creates the internal models by consuming a JSON archive from a previous run session. This provides the same functionality as available in earlier versions viaappendExisting, 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
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:
setAnalysisStrategyin interfaceAnalysisTypeConfigurable- Parameters:
strategy-AnalysisStrategydetermines the type of analysis (dashboard) created for the reporter. Not all reporters will support this setting.
-
setGherkinDialect
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
-
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
Returns an instance ofReportStatswith counts of tests executed by their status (pass, fail, skip etc)- Returns:
- an instance of
ReportStats
-
onAuthorAssigned
-
onCategoryAssigned
-
onDeviceAssigned
-