In software
test automation after completion of the test suite execution we need to have a
report for the execution status and it is one way of evidence for the pass and
fail status of the tests. Extent reports are very rich HTML reports for the
selenium webdriver.. By using these reports we can provide lots of information
to the reports.
Some
advantages of Extent Reports:
1.Status will be shown in the form of PIE
chart.
2.Can give the our own name to the test
method (i.e can change the test method name in the report).
3.Can generate stepwise log information in
the report.
4.Can segregate the tests using Test
Categories.
5.Can give test author name to display in
the report.
6.Can show the screenshots in the report
wherever we need.
7.Can add our own information in the report
(i.e. version of selenium used, Environment information where the test suite
executed).
8.It will give the System information in the
report (i.e. HostName and OS used to execute the test suite.)
Let’s
create Extents Report for one of my sample project “Calculator”.
1.At first
need to add Nuget Pakage for Extents Report.
Reference->Manage
Nuget Packages->Online->ExtentReports
2.Check the
version number, Install 2.41.0
3.Add a XML
File
4.Add below
configuration file into the XML file.
<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>AutomationTesting.in</documentTitle> <!-- report name - displayed at top-nav --> <reportName>Automation Testing Report</reportName> <!-- report headline - displayed at top-nav, after reportHeadline --> <reportHeadline>- QA 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>
5.I have
used a html page for Extents Report which is available in the below link
6.Need to save
that html file by creating a folder in the project.
8.Need to
show the html file path and XML file path in the code.
public ExtentReports StartReport() { string ReportPath = @""; string ReportXMLPath = @""; var extent = new ExtentReports(ReportPath); extent.LoadConfig(ReportXMLPath); return extent; }
LoadConfig() method of ExtentReports class take the XML file path as argument.
9.In test function,need to start the extent reports.
StartTest() method of ExtentReports class is the starting
point of the test and it will return the ExtentTest object.
[Test]
public void TestAddition() { test = extent.StartTest("Addition Test"); var result = calculator.Addition(10, 20); Assert.That(result, Is.EqualTo(30)); test.Log(LogStatus.Pass, "Assert Pass"); }10.In TearDown attribute need to close test.
[TearDown] public void AfterEachTest() { extent.EndTest(test); extent.Flush(); extent.Close(); }EndTest() method of ExtentReports will stop capturing information about the test log.Flush() method of ExtentReports will push/write everything to the document.Close() method of ExtentReports will clear/close all resource of the ExtentReports object.11.After that if we run our test and open the html file we can see the result in Extent Report.
Comments
Post a Comment