anshooarora / extentreports-csharp

Community version of Extent API for .NET has moved to https://github.com/extent-framework/
http://extentreports.com/
Other
47 stars 43 forks source link

ExtentReport creates and replaces new report for each namespace(cs. file) #97

Closed DivAbi closed 6 years ago

DivAbi commented 6 years ago

@anshooarora @karthikbhatnagar

Summary

Extent report gets created for only last ran tests under namespaces.

Expected Behavior

If i have 5 namespcaes( 5 cs file with each has different nunit tests) than i should see all the test in single report.

Current Behavior

Extent report only shows tests from single cs file and doesnt take all other test from different cs file

Sample

Its Nunit framework

using AventStack.ExtentReports; using AventStack.ExtentReports.Reporter; using System.Reflection; using System; using NUnit.Framework; using NUnit.Framework.Interfaces [TestFixture]

public class Test
{
    public ExtentReports extentReport;
    public ExtentTest extentTest;

    public Test()
    {
    }

    [SetUp]
    public void Initialization()
    {
        extentTest = extentReport.CreateTest(TestContext.CurrentContext.Test.Name);

    }
    [OneTimeSetUp]
    protected void Setup()
    {

        {
            string path = Assembly.GetCallingAssembly().CodeBase;

            string actualpath = path.Substring(0, path.LastIndexOf("TestReport"));

            string projectpath = new Uri(actualpath).LocalPath;

            string reportpath = projectpath + "TestReport\\test.html";

            var extentHtml = new ExtentHtmlReporter(reportpath);

            extentHtml.LoadConfig(projectpath + "extent-config.xml");

            extentReport = new ExtentReports();
            extentReport.AttachReporter(extentHtml);

            extentReport.AddSystemInfo("Host name", "ABCD");

            extentReport.AddSystemInfo("Environment", "Automation");

            extentReport.AddSystemInfo("Version", "ABCD");

        }
    }

    /*
            [OneTimeTearDown]
            public void TestFixtureTearDown()
            {

            }
      */
    [TearDown]
    public void GetResult()
    {

        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;
        }

        extentTest.Log(logstatus, "Test ended with " + logstatus + stacktrace);
        extentReport.Flush();
    }

}

}

// Sample code goes here

Environment Details

Screenshots

anshooarora commented 6 years ago

This is for Java but CS way is similar: https://github.com/anshooarora/extentreports-java/blob/master/src/test/java/com/aventstack/extentreports/common/ExtentManager.java

You need to use the above singleton approach so multiple inatances are not created.