Reporting is an important step of test automation as it helps stakeholders understand the outcome of the test case, the status of the application’s health and potential issues.
What are extent reports?
Extent Reports is an open-source reporting library used with test automation tools. It can be integrated with testing frameworks like JUnit and TestNG. Extend Reports generates HTML documents that serve as interactive and detailed test execution reports. It provides reports that can depict results as pie charts along with features such as logging and screenshots. Moreover, TestNG provides a report by default, but they are generally less detailed. Additionally, while TestNG provides default reports, they lack the level of detail and interactivity that Extent Reports offer, such as graphical representations, logs, and screenshots.
How to use extent reports in selenium?
Extent Reports has two major components or classes namely:
- ExtentReports class
- ExtentTest class
Syntax
ExtentReports class generates the HTML reports and accepts two arguments.
First argument is the path where the report has to be generated and the second argument is whether the file has to be overwritten or a new file should be created.
True will be the default value to overwrite all the existing data.
The ExtentTest class logs each individual test step to the HTML report, allowing you to track the progress and results of the test case
The ExtentReports class and ExtentTest class can be used with the below built-in methods:
- startTest: To execute preconditions of a test case
- endTest: To execute postconditions of a test case
- Log: To log the status of each step
- Flush: Flush: This method clears any previous data from the memory and writes the final report to the designated output file.
How to generate reports?
- Add the extentreports-java-2.41.2.jar to the project buildpath.
- Create a new java class and add the below code:
Test execution begins with the startTest() method, annotated with @BeforeClass, which initializes the Extent Reports object. This method sets up the report by specifying the output file location and initializing the test case.
@test methods opens the chrome browser and launches the URL and validates the page Title with the expected and logs the test case status as Pass or Fail. endTest() method executes postconditions of the test case
How to log test steps and results?
Test Status can be PASS, FAIL, SKIP and INFO.
The log() method accepts two arguments, first is test status and second is message to be displayed in the report.
How to Add Screenshots to Extent Report?
Screenshots can be captured in the report if a test fails.
Benefits of using extent reports
- It is open source.
- It can be customized as per the requirements.
- It provides pictorial and pie chart representations of test results
- It can be easily integrated with frameworks like Junit , TestNG and Nunit.
- It allows users to attach screenshots when the test fails.
- It logs the test report for a detailed summary of the tests.
Conclusion:
The significance of reporting in Selenium using ExtentReports is to provide comprehensive and customizable reports. Extent Reports help to communicate and track defects effectively with stakeholders. The final goal is to lead to better testing approaches and faster defect resolution.
Source: This article was originally published at testgrid.io.
Top comments (0)