Skip to main content

Generating Extent Reports in C#





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

Popular posts from this blog

JIRA OverView

What is JIRA? JIRA is a project management tool used for issues and bugs tracking system for all types of testing.The JIRA dashboard consists of many useful functions and features which make handling of issues easy. The following points explain some interesting details of JIRA. • JIRA is an incident management tool. • JIRA is not an acronym, the name 'JIRA' comes from the Japanese word 'Gojira' • JIRA is developed by Australian Company Atlassian • JIRA is a platform independent tool; it can be used with any OS. • JIRA is multi-lingual tool − English, French, German, Japanese, Spanish, etc. • JIRA can be integrated with many other tools like GitHub, Team Foundation Software and many more. • JIRA is a commercial tool and available as a Trial version for a limited time. • To utilize JIRA services, a license is required. Features: JIRA is one the best product management tool which includes: Issue tracking & management: A software application that allows to...

Demo Project (Specflow Setup)

Installation and Setup Steps-->     1.Install SpecFlow for Visual Studio (Open Extensions and Updates) 2. Install SpecFlow NuGet Packages     3. Add Feature File    My Demo Project    Here, I have worked on following story    Story: Discounts on online shopping cart price for loyalty card customers    In order to increase the reward for loyal customers    I want to add 5-10% discounts on the final shopping cart price.    Scenario 1: 5% discount for loyalty card customer    Given a loyalty card customer in online checkout page    When the shopping card total is less than $100    Then 5% discount should be applied to the final shopping cart price.     Create Scenarios    In the feature file, I described what the feature needs to do Every scenario represents a different       ...