Extent Reports Log Generation – CSharp
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:
using NUnit.Framework; using RelevantCodes.ExtentReports; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExtentReportsDemo { [TestFixture] public class CreatingStepLogs { public ExtentReports extent; public ExtentTest test; [OneTimeSetUp] public void StartReport() { string path = System.Reflection.Assembly.GetCallingAssembly().CodeBase; string actualPath = path.Substring(0, path.LastIndexOf("bin")); string projectPath = new Uri(actualPath).LocalPath; string reportPath = projectPath + "Reports\\ExtentStepLogs.html"; extent = new ExtentReports(reportPath, 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"); } [OneTimeTearDown] 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.