Reports play a fundamental role when it comes to TESTING. Tester can now know the real-time reports of test suit execution. Reports made ease to know the ratio of Pass? : Fail? post-test suit execution and it is the only documentation to know about test execution results.
Everyone wish to see the detailed description of the test results. Don’t you? here is the solution for it. And, let us see how these reports can be achieved? in Selenium C# – NUnit framework automation testing.
To achieve detailed test execution results as HTML reports we need to rely on third party tool called => Extent Reports. These reports provide decent narration of test execution results and are depicted in PIE chart.
How to Reference Extent Reports in MS Visual Studio 2015?
Extent Reports can be directly referenced via NuGet Gallery:
1: Reference => Manage NuGet Packages.
2: Install the Extent Reports from NuGet gallery.
3: Extent Reports reference is now added to your project.
How to Initialize Reports?
=> Instance of Extent Reports should be created to initialize the reports.
ExtentReports – Used to generate HTML reports.
ExtentTest – Used to create test log – pass, fail, skip etc…
NamesSpaces: RelevantCodes.ExtentReports;
=> Create a folder in the project path/current solution to store the HTML report (execution results).
Following is the complete class for extent reports:
[TestFixture]
class ExtentReports
{
//Instance of extents reports
public static ExtentReports extent;
public static ExtentTest test;
[OneTimeSetUp]
Public void StartReport()
{
//To obtain the current solution path/project path
string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
//Append the html report file to current project path
string reportPath = projectPath + "Reports\TestRunReport.html";
//Boolean value for replacing exisisting report
extent = new ExtentReports(reportPath, true);
//Add QA system info to html report
extent.AddSystemInfo("Host Name", "YourHostName")
.AddSystemInfo("Environment", "YourQAEnvironment")
.AddSystemInfo("Username", "YourUserName");
//Adding config.xml file
extent.LoadConfig(projectPath + "Extent-Config.xml"); //Get the config.xml file from http://extentreports.com
}
[TearDown]
public void AfterClass()
{
//StackTrace details for failed Testcases
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stackTrace = "<pre>" + TestContext.CurrentContext.Result.StackTrace + "</pre>";
var errorMessage = TestContext.CurrentContext.Result.Message;
if(status == TestStatus.Failed)
{
test.Log(LogStatus.Fail, status + errorMessage);
}
//End test report
extent.EndTest(test);
driver.Quit();
}
[OneTimeTearDown]
public void EndReport()
{
//End Report
extent.Flush();
extent.Close();
}
Now, let’s see how to create a test method.
Note: The first statement in your test method should be extent reports to start reporting your test method.
Here, I have demonstrated simple Assert test method to create extent reports.
[Test]
public void SampleReporting(string browserName)
{
//Start Report
test = extent.StartTest("SampleReporting"); //”SampleReporting” TestMethod name
//Log 'info'
test.Log(LogStatus.Info, "Sample Reporting demo");
//Pass scenario
Assert.AreEqual(10,10);
test.Log(LogStatus.Pass, "Test Passed");
//Fail scenario
Assert.IsTrue(false);
test.Log(LogStatus.Fail, "Test Failed");
}
Post running test method, the test execution report looks as shown below:
And, the PIE chart representation of test execution result looks as shown below:
Hope, everyone finds this blog useful for depicting “Text Execution Results”.
Please do subscribe to our blogs and keep yourself updated with the new posts.
For more information on extent reports, visit site: http://extentreports.com
Happy Reporting
Happy Testing