'Selenium C# Extent report is not generating HTML file in the specified folder

I am trying to generate a report in HTML using Extent report (version="3.1.3") for Selenium Webdriver C#, but in the specified folder i am not able to see the HTML file after successful execution of test script.

It would be great if you could help me in identifying what is wrong and provide a solution for this issue.

Thanks in advance.

Please find below for the code snippet.

namespace Selenium_Demo_01
 {
[TestFixture]
public class Demo01
{
    IWebDriver driver;
    Program dataDriven = new Program();

    public ExtentReports extent;
    public ExtentTest test;

    [OneTimeSetUp]
    public void ClassSetup()
    {
        var reportPath = new ExtentHtmlReporter(@"I:\Selenium\VS Project 
                                            files\Selenium_Demo_01\
                                                       Selenium_Demo_01\Reports\Demo_Report_01.html");

        extent = new ExtentReports();
        extent.AttachReporter(reportPath);
    }

    [Test]
    public void test_D365Login()
    {
        test = extent.CreateTest("test_D365Login");

        string webTitle, webTitle1;

        //Get web page Title
        driver.Url = appURL;
        webTitle = driver.Title;
        System.Console.WriteLine(webTitle);

        Assert.AreEqual(title1, webTitle);
        test.Pass("Assertion passed");

        //Get web page Title
        webTitle1 = driver.Title;
        System.Console.WriteLine(webTitle1);

        Assert.AreEqual(title2, webTitle1);
        test.Pass("Assertion passed");
    }

    [TearDown]
    public void closeBrowser()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
                ? ""
                : string.Format("{0}", 
                       TestContext.CurrentContext.Result.StackTrace);
        Status logstatus;

        switch (status)
        {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                break;
            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;
            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;
            default:
                logstatus = Status.Pass;
                break;
        }

        test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
        extent.RemoveTest(test);
        extent.Flush();
        driver.Close();
    }

}

Extent-config.xml

<?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</documentTitle>

    <chartVisibilityOnOpen>true</chartVisibilityOnOpen>

    <!-- report name - displayed at top-nav -->
    <reportName>Automation Report - Shashank R</reportName>

    <!-- location of charts in the test view -->
    <!-- top, bottom -->
    <testViewChartLocation>bottom</testViewChartLocation>

    <!-- custom javascript -->
    <scripts>
        <![CDATA[
            $(document).ready(function() {

            });
        ]]>
    </scripts>

    <!-- custom styles -->
    <styles>
        <![CDATA[

        ]]>
    </styles>
</configuration>



Solution 1:[1]

Please follow the step and check whether Report is generating or not, Make sure your Test execution completed correctly, And extent.fluch() was call. Else, Extent Report can't generate.

  1. Create Folder in your project Workspace named as "eReport"
  2. Create variable name as reportLocation = "./eReport/" + "TestReport.html";
  3. Pass reportLocation variable to ExtentHTMlReport method,

    var reportPath = new ExtentHtmlReporter(reportLocation);

And further you may check, it is generated or not.

You may try with Basic example from their official Doc, http://extentreports.com/docs/versions/3/net/#examples

Solution 2:[2]

Please find below for the code snippet:

[TestFixture]
class Demo
{
    public ExtentReports extent;
    public ExtentTest test;

    [SetUp]
    public void TestSetup()
    {
        var reportPath = new ExtentHtmlReporter
            (@"C:\Users\Administrator\Documents\visual studio 2015\Projects\Selenium_D365\Selenium_D365\eReports\Demo_Report_01.html");
        //var reportLocation = "./Reports/" + "TestReport.html";
        //var reportPath = new ExtentHtmlReporter(reportLocation);
        extent = new ExtentReports();
        extent.AttachReporter(reportPath);
    }

    [Test]
    public void test_D365Login()
    {
        test = extent.CreateTest("test_D365Login");

        Assert.IsTrue(true);
        test.Pass("Assertion passed");
    }

    [TearDown]
    public void TestCleanup()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace);
        Status logstatus = Status.Pass;

        test.Log(logstatus, "Test ended with " + status + stacktrace);

        extent.RemoveTest(test);
        extent.Flush();
    }
}

Solution 3:[3]

You have load the extent-config file location in HTML object.

reportPath.LoadConfig("Extent-config.xml")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ishita Shah
Solution 2 Shashank R
Solution 3 Aleks Andreev