Extent Reports Log Generation – Java – Version3
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 Status.INFO as first parameter in the log() method. And we need to use Status.PASS for the passed test case and Status.FAIL for the failed test cases.
Not only log the information in the report as plain text, along with this we can also apply some backgrounds to that information using Label concept in the extent reports. By using this we can apply different colours to the log information.
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.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.Status; import com.aventstack.extentreports.markuputils.ExtentColor; import com.aventstack.extentreports.markuputils.MarkupHelper; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; public class CreatingLogs { ExtentHtmlReporter htmlReporter; ExtentReports extent; ExtentTest test; @BeforeTest public void config() { htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html"); extent = new ExtentReports(); extent.attachReporter(htmlReporter); } @Test public void logsGeneration() { test = extent.createTest("logsGeneration"); test.log(Status.INFO,"createTest() method will return the ExtentTest object"); test.log(Status.INFO, "I am in actual Test"); test.log(Status.INFO, "We can write the actual test logic in this Test"); // Using Labels test.log(Status.INFO, MarkupHelper.createLabel("*************** Using Labels ***************", ExtentColor.RED)); test.log(Status.INFO, MarkupHelper.createLabel("This is Test Logger 1", ExtentColor.BLUE)); test.log(Status.INFO, MarkupHelper.createLabel("This is Test Logger 2", ExtentColor.BLUE)); test.log(Status.INFO, MarkupHelper.createLabel("This is Test Logger 3", ExtentColor.BLUE)); test.log(Status.INFO, MarkupHelper.createLabel("This is Test Logger 4", ExtentColor.BLUE)); } @AfterTest public void tearDown() { extent.flush(); } }
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.