Extent Reports Log Generation – Java
Extent Reports Log Generation will discuss about how to generate log steps in the Extent Reports. While running the test suite user want to log some information about the execution in the report. This information will help the user to understand the test step execution flow and any failures during the test suite execution.
By using Extent Reports we can generate logs in the HTML report. For this we need use the log() method of the ExtentTest Class. By using this method not only log the step information, we can provide the PASS, FAIL and SKIP information of the particular test case. To log the information we need to use the LogStatus.INFO as first parameter in the log() method. And we need to use LogStatus.PASS for the passed test case and LogStatus.FAIL for the failed test cases.
Below is the sample program for generating step logs in the report:
import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; public class CreatingStepLogs { ExtentReports extent; ExtentTest test; @BeforeTest public void config() { extent = new ExtentReports(System.getProperty("user.dir") +"/test-output/ExtentStepLogs.html", true); } @Test public void stepLogsGeneration() { test = extent.startTest("stepLogsGeneration"); test.log(LogStatus.INFO, "startTest() method will return the Extent Test object "); test.log(LogStatus.INFO, "I am in actual test method"); test.log(LogStatus.INFO, "We Can Write The Actual Test Logic In This Test"); } @AfterTest public void tearDown() { extent.endTest(test); test.log(LogStatus.INFO, "endTest() method will stop capturing information about the test log"); extent.flush(); test.log(LogStatus.INFO, "flush() method of ExtentReports wil push/write everything to the document"); test.log(LogStatus.INFO, "close() method will clear/close all resource of the ExtentReports object"); extent.close(); } }
In the above program we have written so many test.log methods to log the information into the extent reports. This information will logged in the report with time stamp.
Below is the output/report of the above program.
Please watch the YouTube video of this blog for better understanding.