Extent Reports - Implement simply Extent Report into your C# page object model. Please follow flowing steps to get this done.
Assuming Page Object Model Should Contain,
- Test Suite Include All test Methods.
- PO classes Included All elements related to the page and all action methods related to the page.
- Installing Extent report by reference
Solution Explorer -> References ->Manage nugget packages -> type ‘extentreports’ in browse and click ok (Take Version 2.41.0)
- Create One Time Setup in your Test Class (Basically where you're going to run your test)
public ExtentTest test;
public ExtentReports extent;
[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\\AutomationTestingReport.html";
extent = new ExtentReports(reportPath, true);
extent
.AddSystemInfo("Host Name", "MALINDA")
.AddSystemInfo("Environment", "TEST")
.AddSystemInfo("User Name", "MALINDAW");
extent.LoadConfig(projectPath + "extent-config.xml");
BasicReport brObj = new BasicReport();
brObj.setExtentReport(extent);
}
- Setup your test Method in Test Class to generate the information for the Report
public void testExtendReportTC()
{
BasicReport BR = new BasicReport();
test = extent.StartTest("Write your Test Method Name");
BR.setExtentTest(test);
//Write your Test
test.Log(LogStatus.Pass, "Assert Pass as condition is True");
}
- Create a new folder on the solution for report path
"Reports\\AutomationTestingReport.html"
- Create new Xml file (extent-config.xml) for to setup Extend Report Configuration & Information
<?xml version="1.0" encoding="UTF-8"?><extentreports> <configuration> <!-- report theme --> <!-- standard, dark --> <theme>standard</theme> <!-- document encoding --> <!-- defaults to UTF-8 --> <encoding>UTF-8</encoding> <!-- protocol for script and stylesheets --> <!-- defaults to https --> <protocol>https</protocol> <!-- title of the document --> <documentTitle>Automation Testing Status</documentTitle> <!-- report name - displayed at top-nav --> <reportName>Automation Testing Report</reportName> <!-- report headline - displayed at top-nav, after reportHeadline --> <reportHeadline>- Test Environment</reportHeadline> <!-- global date format override --> <!-- defaults to yyyy-MM-dd --> <dateFormat>yyyy-MM-dd</dateFormat> <!-- global time format override --> <!-- defaults to HH:mm:ss --> <timeFormat>HH:mm:ss</timeFormat> <!-- custom javascript --> <scripts> <![CDATA[ $(document).ready(function() { }); ]]> </scripts> <!-- custom styles --> <styles> <![CDATA[ ]]> </styles> </configuration></extentreports>
- Create New Class(Basic Report) to keep all getter & setter methods.
public class BasicReport
{
public static ExtentTest test;
public static ExtentReports extent;
public void setExtentTest(ExtentTest setTest)
{
test = setTest;
}
public void setExtentReport(ExtentReports setReport)
{
extent = setReport;
}
public ExtentTest getExtentTest()
{
return test;
}
public ExtentReports getExtentReports()
{
return extent;
}
}
- Create new object from BasicReport class and Declare Variable from ExtentTest in your Page Object Class.
BasicReport brOBJ = new BasicReport();
public ExtentTest test;
- Initialize Basic Report Object(brOBJ) inside your test method which is in the Page Object Class and Add Step Log to Identify each step in your Test script.
public void addFirstName(string firstName)
{
brOBJ = new BasicReport();
test = brOBJ.getExtentTest();
test.Log(LogStatus.Info, "Enter FirstName");
TXT_FirstName.SendKeys(firstName);
}
- Setup TearDown according do the any failures occurs and create OneTime tear down for to stop capturing information about the test logs and push/write everything to the document.
[[TearDown]
public void TestTearDown()
{
BasicReport BRN = new BasicReport();
test = BRN.getExtentTest();
extent = BRN.getExtentReports();
driver.close();
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, stackTrace + errorMessage);
}
extent.EndTest(test);
}
[OneTimeTearDown]
public void EndReport()
{
extent.Flush();
extent.Close();
}
Good one..Thanks for sharing..keep update best selenium training in chennai
ReplyDeletebest selenium training institute in chennai