Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for .NET Core #43

Closed
brunoj1 opened this issue Feb 25, 2019 · 39 comments
Closed

Support for .NET Core #43

brunoj1 opened this issue Feb 25, 2019 · 39 comments
Labels
enhancement New feature or request

Comments

@brunoj1
Copy link

brunoj1 commented Feb 25, 2019

Hello,

I´m having trouble to implement ExtentReport on a .NET Core application, only the RazorEngine package is on .NET Framework.
There is any sollution for this problem?

Thanks in advance

@foursyth
Copy link

Since RazorEngine is a required dependency of ExtentReports, it would help if it supports .Net Core before any work happens from our end. It is currently an open issue on their end.. I would suggest opening a ticket for .NET core when RazorEngine is ready.

@foursyth
Copy link

@anshooarora this may be closed

@vivek201
Copy link

@anshooarora It looks like the RazorEngine project is on a hiatus Antaris/RazorEngine#535 (comment). I don't suppose there are any plans on moving to a new one?

@foursyth
Copy link

@anshooarora I feel we can keep this open as slow-burner until a resolution is in sight.

@vivek201 feel free to recommend alternatives that can be used

@Samil2018
Copy link

you can use https://www.nuget.org/packages/ExtentReports.Core

read: https://github.com/simplytest/extentreports-csharp

@brunoj1
Copy link
Author

brunoj1 commented May 2, 2019

@felipeotarola
Copy link

@MaheshGooner
Copy link

@felipeotarola @brunoj1 @Samil2018 when i try to use this package with Specflow 3 i get some warning like ScenarioContext.Current is obsolete and although i don't get any error reports are not generated. Do you suggest anything ? or is purely that it does not support Specflow 3 yet ?

@felipeotarola
Copy link

felipeotarola commented Jun 12, 2019

@MaheshGooner
Yes it works, but as you say the method is obsolete, so you need to rewrite some.
this is how I fixed that.
`[Binding]
public class TestInitialize
{
private static ExtentTest featureName;
private static ExtentTest scenario;
private static ExtentReports extent;

    private Settings _settings;
    private readonly ScenarioContext _scenarioContext;
    private readonly IConfiguration _configuration;

    public TestInitialize(Settings settings, ScenarioContext scenarioContext)
    {
        _settings = settings;
        _scenarioContext = scenarioContext;
        _configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();
    }

    [BeforeScenario]
    public void TestSetup()
    {
        _settings.BaseUrl = new Uri(_configuration["BaseUrl"]);
        _settings.RestClient.BaseUrl = _settings.BaseUrl;
     }


    [BeforeTestRun]
    public static void InitializeReport()
    {
        var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
        var file = Path.Combine(solutionDir, "../..", "Reports", "ExtentReports", "ExtentReport.html");
        var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
        var htmlReporter = new ExtentHtmlReporter(path);
        extent = new ExtentReports();
        extent.AttachReporter(htmlReporter);
    }

    [AfterTestRun]
    public static void TearDownReport()
    {
        extent.Flush();
    }

    [BeforeFeature]
    public static void BeforeFeature(FeatureContext featureContext)
    {
        featureName = extent.CreateTest<Feature>(featureContext.FeatureInfo.Title);
    }

    [AfterStep]
    public void InsertReportingSteps()
    {
        var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();
        if (_scenarioContext.TestError == null)
        {
            if (stepType == "Given")
                scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
            else if (stepType == "When")
                scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
            else if (stepType == "Then")
                scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
            else if (stepType == "And")
                scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
        }
        else if (_scenarioContext.TestError != null)
        {
            if (stepType == "Given")
                scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(_scenarioContext.TestError.Message);
            else if (stepType == "When")
                scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(_scenarioContext.TestError.Message);
            else if (stepType == "Then")
                scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(_scenarioContext.TestError.Message);
        }
    }

    [BeforeScenario]
    public void Initialize()
    { 
        scenario = featureName.CreateNode<Scenario>(_scenarioContext.ScenarioInfo.Title);
    }
}`

@MaheshGooner
Copy link

MaheshGooner commented Jun 12, 2019

@felipeotarola can you please give the imports as well ? what are Settings ? ConfigurationBuilder() ?

In my case i have the following two classes

Hooks.cs

using System;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Gherkin.Model;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Bindings;
using SbAutomation.ExtensionMethods;

namespace SbAutomation.Common
{
    [Binding]
    public class Hooks
    {
        private static ExtentTest _feature;
        private static ExtentTest _scenario;
        private static AventStack.ExtentReports.ExtentReports _extent;
        private static readonly string PathReport = @"C:\Users\xxxx\Desktop\Automation\SbAutomation\ExtentReport.html";

        [BeforeTestRun]
        public static void ConfigureReport()
        {
            var reporter = new ExtentHtmlReporter(PathReport);
            _extent = new AventStack.ExtentReports.ExtentReports();
            _extent.AttachReporter(reporter);
        }

        [BeforeFeature]
        public static void CreateFeature()
        {
            _feature = _extent.CreateTest<Feature>(FeatureContext.Current.FeatureInfo.Title);
        }

        [BeforeScenario]
        public static void CreateScenario()
        {
            _scenario = _feature.CreateNode<Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
        }

        [AfterStep]
        public static void InsertReportingSteps()
        {
            switch (ScenarioStepContext.Current.StepInfo.StepDefinitionType)
            {
                case StepDefinitionType.Given:
                    _scenario.StepDefinitionGiven();
                    break;

                case StepDefinitionType.Then:
                    _scenario.StepDefinitionThen();
                    break;

                case StepDefinitionType.When:
                    _scenario.StepDefinitionWhen();
                    break;
            }
        }

        [AfterTestRun]
        public static void FlushExtent()
        {
            _extent.Flush();
            System.Diagnostics.Process.Start(PathReport);
        }
    }
}

ScenarioExtensionMethods.cs

using System;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Gherkin.Model;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Bindings;

namespace SbAutomation.ExtensionMethods
{
    public static class ScenarioExtensionMethod
    {
        private static ExtentTest CreateScenario(ExtentTest extent, StepDefinitionType stepDefinitionType)
        {
            var scenarioStepContext = ScenarioStepContext.Current.StepInfo.Text;

            switch (stepDefinitionType)
            {
                case StepDefinitionType.Given:
                    return extent.CreateNode<Given>(scenarioStepContext);

                case StepDefinitionType.Then:
                    return extent.CreateNode<Then>(scenarioStepContext);

                case StepDefinitionType.When:
                    return extent.CreateNode<When>(scenarioStepContext);
                default:
                    throw new ArgumentOutOfRangeException(nameof(stepDefinitionType), stepDefinitionType, null);
            }
        }

        private static void CreateScenarioFailOrError(ExtentTest extent, StepDefinitionType stepDefinitionType)
        {
            var error = ScenarioContext.Current.TestError;

            if (error.InnerException == null)
            {
                CreateScenario(extent, stepDefinitionType).Error(error.Message);
            }
            else
            {
                CreateScenario(extent, stepDefinitionType).Fail(error.InnerException);
            }
        }

        public static void StepDefinitionGiven(this ExtentTest extent)
        {
            if (ScenarioContext.Current.TestError == null)
                CreateScenario(extent, StepDefinitionType.Given);
            else
                CreateScenarioFailOrError(extent, StepDefinitionType.Given);
        }

        public static void StepDefinitionWhen(this ExtentTest extent)
        {
            if (ScenarioContext.Current.TestError == null)
                CreateScenario(extent, StepDefinitionType.When);
            else
                CreateScenarioFailOrError(extent, StepDefinitionType.When);
        }

        public static void StepDefinitionThen(this ExtentTest extent)
        {
            if (ScenarioContext.Current.TestError == null)
                CreateScenario(extent, StepDefinitionType.Then);
            else
                CreateScenarioFailOrError(extent, StepDefinitionType.Then);
        }
    }
}

I get the warning scenariocontext.current is obsolete please get the scenariocontext via context injection in ScenarioExtensionMethods class with no errors. and it does not generate the report

@felipeotarola
Copy link

@MaheshGooner
Sorry this are my imports
using ApiTests.Base;
using AventStack.ExtentReports.Reporter;
using System;
using TechTalk.SpecFlow;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Gherkin.Model;
using System.IO;
using Microsoft.Extensions.Configuration;
using NUnit.Framework;
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
using RestSharp;

Settings and ConfigurationBuilder() are custom methods that I use in my framework. you can skip dem :)

It looks like you are missing
private readonly ScenarioContext _scenarioContext;
in your Hook Class.

And your CreateFeature should look like this.

      [BeforeFeature]
       public static void CreateFeature(FeatureContext featureContext)
       {
           _feature = _extent.CreateTest<Feature>(featureContext.FeatureInfo.Title);
       }

@MaheshGooner
Copy link

@felipeotarola i still din't get it right. As my hooks class is static class i am unable to use context injection. do you have the complete example of the implementation of Extent reports for .net core ? sorry for asking too many details but i'm new to .net

@pooja4099
Copy link

pooja4099 commented Jul 28, 2019

Hi @felipeotarola,
I tried following the steps that you have mentioned but I keep getting the below exception @extent.flush();... Any idea? thanks in advance

(I already have RazorEngine.NetCore added to the NuGet).
System.TypeLoadException
HResult=0x80131522
Message=Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Source=RazorEngine
StackTrace:
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType_Windows(TypeContext context)
at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter) at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush(ReportAggregates reportAggregates) at AventStack.ExtentReports.Core.ExtentObservable.<>c__DisplayClass59_0.<NotifyReporters>b__0(IExtentReporter x) at System.Collections.Generic.List1.ForEach(Action`1 action)
at AventStack.ExtentReports.Core.ExtentObservable.NotifyReporters()
at AventStack.ExtentReports.Core.ExtentObservable.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at CSharpUI.steps.Hooks.After() 120

@archVille
Copy link

Very helpful guys, I migrated from 3 to 4, using .net core and trying to find a way to make it work but couldnt find any help anywhere.

Big help, thanks!

@MaheshGooner
Copy link

@archVille were you able to include screenshots to the extent reports ?

@archVille
Copy link

@archVille were you able to include screenshots to the extent reports ?

I havent reached that stage yet, but it is in my 'TODO' list as I previously had screenshots functionality implemented and need to migrate them with the same way.
I will keep you posted - or if any of you implement this, just drop a message here.

@MaheshGooner
Copy link

Thanks @archVille. I don't get that working yet. I can take screenshot but it does not attch it to the report by calling test.Fail("details", MediaEntityBuilder.CreateScreenCaptureFromPath("screenshot.png").Build());

Would be helpful if someone gets that to work and post. Thanks

@lucascologni
Copy link

Did you guys got to run ExtentReports with .net core?

I installed a lot of packages Razor, extensions, etc, but even then I'm getting this error

Message=Could not load type 'System.Security.Principal.WindowsImpersonationContext'

Is there any way to run extent reports with .net core? Or it's not possible yet?

Please, help me

thank you very much!

@MaheshGooner
Copy link

yeah. i got that to work apart from not being able to attach screenshots. Below is my configuration

using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using AventStack.ExtentReports.Reporter;
using NUnit.Framework;
using SbAutomation.Common;

namespace SbAutomation.Features
{
    [SetUpFixture]
    public class TestSetup
    {
        private readonly string _pathReport = $"{AppDomain.CurrentDomain.BaseDirectory}index.html";

        [OneTimeSetUp]
        public void RunBeforeAnyTests()
        {
            var reporter = new ExtentHtmlReporter(_pathReport);
            Hooks.Extent = new AventStack.ExtentReports.ExtentReports();
            Hooks.Extent.AttachReporter(reporter);
        }

        [OneTimeTearDown]
        public void RunAfter()
        {
            Hooks.Extent.Flush();
            //TODO: this should be wrapped into more platform agnostic code. Also commented to avoid error on gitlab-ci
            //Process.Start(@"cmd.exe ", $@"/c {AppDomain.CurrentDomain.BaseDirectory}index.html");
        }
    }
}
using System;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Bindings;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Gherkin.Model;
using AventStack.ExtentReports.Reporter;
using SbAutomation.ExtensionMethods;

namespace SbAutomation.Common
{
    [Binding]
    public class Hooks
    {
        private static ExtentTest _feature;
        private static ExtentTest _scenario;
        public static AventStack.ExtentReports.ExtentReports Extent;
        //private static readonly ScenarioContext _scenarioContext;

        [BeforeTestRun]
        public static void ConfigureReport()
        {
        }

        [BeforeFeature]
        public static void CreateFeature(FeatureContext featureContext)
        {
            _feature = Extent.CreateTest<Feature>(featureContext.FeatureInfo.Title);
        }

        [BeforeScenario]
        public static void CreateScenario(ScenarioContext _scenarioContext)
        {
            _scenario = _feature.CreateNode<Scenario>(_scenarioContext.ScenarioInfo.Title);
        }

        [AfterStep]
        public static void InsertReportingSteps()
        {
            switch (ScenarioStepContext.Current.StepInfo.StepDefinitionType)
            {
                case StepDefinitionType.Given:
                    _scenario.StepDefinitionGiven();
                    break;

                case StepDefinitionType.Then:
                    _scenario.StepDefinitionThen();
                    break;

                case StepDefinitionType.When:
                    _scenario.StepDefinitionWhen();
                    break;
            }
        }

        [AfterTestRun]
        public static void FlushExtent()
        {

        }
    }
}

sorry for being lazy and pasting all the dependencies

<ItemGroup>
    <PackageReference Include="Nunit" Version="3.11.0" />
    <PackageReference Include="NUnit.Console" Version="3.10.0" />
    <PackageReference Include="NUnit.ConsoleRunner" Version="3.10.0" />
    <PackageReference Include="NUnit.Extension.NUnitV2Driver" Version="3.7.0" />
    <PackageReference Include="NUnit.Extension.NUnitV2ResultWriter" Version="3.6.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
    <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
    <PackageReference Include="Selenium.Chrome.WebDriver" Version="76.0.0" />
    <PackageReference Include="BoDi" Version="1.4.1" />
    <PackageReference Include="SpecFlow" Version="3.0.220" />
    <PackageReference Include="HtmlAgilityPack" Version="1.8.4" />
    <PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.0.220" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
    <PackageReference Include="System.Buffers" Version="4.5.0" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
    <PackageReference Include="System.ValueTuple" Version="4.5.0" />
    <PackageReference Include="gherkin" Version="6.0.0" />
    <PackageReference Include="Utf8Json" Version="1.3.7" />
    <PackageReference Include="HttpClientFactory" Version="1.0.1" />
    <PackageReference Include="unirest-netcore20" Version="1.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="ExtentReports.Core" Version="1.0.2" />
    <PackageReference Include="MongoDB.Bson" Version="2.8.1" />
    <PackageReference Include="MongoDB.Driver" Version="2.8.1" />
    <PackageReference Include="MongoDB.Driver.Core" Version="2.8.1" />
    <PackageReference Include="RazorEngine.NetCore" Version="2.2.2" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
    
  </ItemGroup>

@lucascologni
Copy link

lucascologni commented Sep 30, 2019

@MaheshGooner , I'm using x unit, so I don't have [BeforeTestRun], [BeforeFeature] annotations, so I will try to do the same you did.

So, did you download nuget all of these packages below using nuget? These are the required packages to run the Extent Reports?

<PackageReference Include="ExtentReports.Core" Version="1.0.2" />
<PackageReference Include="MongoDB.Bson" Version="2.8.1" />
<PackageReference Include="MongoDB.Driver" Version="2.8.1" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.8.1" />
<PackageReference Include="RazorEngine.NetCore" Version="2.2.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />

thanks!

@MaheshGooner
Copy link

@lucascologni That's correct. And yeah i used Nunit Test project.

@lucascologni
Copy link

Hi, I got to generate the extent reports, but it's generating 2 files.

index.html
dashboard.html

But I created with the name "ReportTest.html" but the name was not set.

Do you know what can it be ?

    public static void CreateReport(string reportName)
    {
        ExtentHtmlReporter extentHtmlReporter = new ExtentHtmlReporter(GetReportsClassLibraryPath() + reportName + ".html");

        _extentReport = new AventStack.ExtentReports.ExtentReports();
        _extentReport.AttachReporter(extentHtmlReporter);

        AddReportSystemInfo();

        var test = _extentReport.CreateTest("ExtentTestCase");
        test.Log(Status.Info, "Step 1: Test Case Starts.");
        test.Log(Status.Pass, "Step 1: Test Case for Pass.");
        test.Log(Status.Fail, "Step 3: Test Case Failed.");

        _extentReport.Flush();
    }

private static string GetReportsClassLibraryPath() => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..\..\..\");

Thanks!

@gitsaquib
Copy link

Which version of ExtentReports this fix is available in?

@lucascologni
Copy link

Which version of ExtentReports this fix is available in?

Are you talking about the report name that is not applying ? If so, I coudn't find any answer about it

@gitsaquib
Copy link

Which version of ExtentReports this fix is available in?

Are you talking about the report name that is not applying ? If so, I coudn't find any answer about it

I am struggling with Visual Studio code with an issue. Following is the project file

Exe netcoreapp3

And I get following error on report.Flush();

System.TypeLoadException : Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Stack Trace:
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType_Windows(TypeContext context)
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter) at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag) at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush(ReportAggregates reportAggregates) at AventStack.ExtentReports.Core.ExtentObservable.<>c__DisplayClass59_0.<NotifyReporters>b__0(IExtentReporter x) at System.Collections.Generic.List1.ForEach(Action`1 action)
at AventStack.ExtentReports.Core.ExtentObservable.NotifyReporters()
at AventStack.ExtentReports.Core.ExtentObservable.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at TestAutomation.LogMe.CloseReport() in d:\Users\mohd.saquib\CSharpProjectUsingVSC\Core\LogMe.cs:line 88
at TestAutomation.TestAmex.TC_01_Amex_CardTitle() in d:\Users\mohd.saquib\CSharpProjectUsingVSC\TestAmex.cs:line 36

Test Run Failed.
Total tests: 1
Failed: 1
Total time: 51.3778 Seconds

@vinuthakbapu
Copy link

Thanks @archVille. I don't get that working yet. I can take screenshot but it does not attch it to the report by calling test.Fail("details", MediaEntityBuilder.CreateScreenCaptureFromPath("screenshot.png").Build());

Would be helpful if someone gets that to work and post. Thanks

@MaheshGooner Is the attachment issue fixed?? Any workaround exist

@MaheshGooner
Copy link

Thanks @archVille. I don't get that working yet. I can take screenshot but it does not attch it to the report by calling test.Fail("details", MediaEntityBuilder.CreateScreenCaptureFromPath("screenshot.png").Build());
Would be helpful if someone gets that to work and post. Thanks

@MaheshGooner Is the attachment issue fixed?? Any workaround exist

@vinuthakbapu I have not worked on it after that so no update. But if you can get it work do let me know please. Would be useful

@anshooarora anshooarora added the enhancement New feature or request label Dec 26, 2019
@anshooarora anshooarora reopened this Dec 26, 2019
@anshooarora
Copy link
Member

Official .NET Core/Standard release will be available soon. Some ports from the Java version are now available too. Initial:

https://github.com/extent-framework/extentreports-csharp/tree/net-core

@anshooarora
Copy link
Member

Support for .Net Core/Standard is available starting 4.1.0-alpha.

@TJEvans
Copy link

TJEvans commented Feb 19, 2020

@anshooarora Is the alpha package available anywhere, potentially as a pre-release to try out?

@ak200275
Copy link

ak200275 commented Mar 3, 2020

Hi, I got to generate the extent reports, but it's generating 2 files.

index.html
dashboard.html

But I created with the name "ReportTest.html" but the name was not set.

Do you know what can it be ?

    public static void CreateReport(string reportName)
    {
        ExtentHtmlReporter extentHtmlReporter = new ExtentHtmlReporter(GetReportsClassLibraryPath() + reportName + ".html");

        _extentReport = new AventStack.ExtentReports.ExtentReports();
        _extentReport.AttachReporter(extentHtmlReporter);

        AddReportSystemInfo();

        var test = _extentReport.CreateTest("ExtentTestCase");
        test.Log(Status.Info, "Step 1: Test Case Starts.");
        test.Log(Status.Pass, "Step 1: Test Case for Pass.");
        test.Log(Status.Fail, "Step 3: Test Case Failed.");

        _extentReport.Flush();
    }

private static string GetReportsClassLibraryPath() => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "......");

Thanks!

Did you get solution to this? I am facing the same issue

@njd868
Copy link

njd868 commented Mar 4, 2020

Which version of ExtentReports this fix is available in?

Are you talking about the report name that is not applying ? If so, I coudn't find any answer about it

I am struggling with Visual Studio code with an issue. Following is the project file

Exe netcoreapp3
And I get following error on report.Flush();

System.TypeLoadException : Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Stack Trace:
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType_Windows(TypeContext context)
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter) at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag) at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush(ReportAggregates reportAggregates) at AventStack.ExtentReports.Core.ExtentObservable.<>c__DisplayClass59_0.<NotifyReporters>b__0(IExtentReporter x) at System.Collections.Generic.List1.ForEach(Action`1 action)
at AventStack.ExtentReports.Core.ExtentObservable.NotifyReporters()
at AventStack.ExtentReports.Core.ExtentObservable.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at TestAutomation.LogMe.CloseReport() in d:\Users\mohd.saquib\CSharpProjectUsingVSC\Core\LogMe.cs:line 88
at TestAutomation.TestAmex.TC_01_Amex_CardTitle() in d:\Users\mohd.saquib\CSharpProjectUsingVSC\TestAmex.cs:line 36

Test Run Failed.
Total tests: 1
Failed: 1
Total time: 51.3778 Seconds

Was there ever a solution for this?

@ak200275
Copy link

ak200275 commented Mar 4, 2020

Hi, I got to generate the extent reports, but it's generating 2 files.

index.html
dashboard.html

But I created with the name "ReportTest.html" but the name was not set.

Do you know what can it be ?

    public static void CreateReport(string reportName)
    {
        ExtentHtmlReporter extentHtmlReporter = new ExtentHtmlReporter(GetReportsClassLibraryPath() + reportName + ".html");

        _extentReport = new AventStack.ExtentReports.ExtentReports();
        _extentReport.AttachReporter(extentHtmlReporter);

        AddReportSystemInfo();

        var test = _extentReport.CreateTest("ExtentTestCase");
        test.Log(Status.Info, "Step 1: Test Case Starts.");
        test.Log(Status.Pass, "Step 1: Test Case for Pass.");
        test.Log(Status.Fail, "Step 3: Test Case Failed.");

        _extentReport.Flush();
    }

private static string GetReportsClassLibraryPath() => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "......");

Thanks!

you can use ExtentV3HtmlReporter instead of ExtentHtmlReporter and it will be ok. it worked for me

@NamanNacedo
Copy link

Hi, I got to generate the extent reports, but it's generating 2 files.
index.html
dashboard.html
But I created with the name "ReportTest.html" but the name was not set.
Do you know what can it be ?

    public static void CreateReport(string reportName)
    {
        ExtentHtmlReporter extentHtmlReporter = new ExtentHtmlReporter(GetReportsClassLibraryPath() + reportName + ".html");

        _extentReport = new AventStack.ExtentReports.ExtentReports();
        _extentReport.AttachReporter(extentHtmlReporter);

        AddReportSystemInfo();

        var test = _extentReport.CreateTest("ExtentTestCase");
        test.Log(Status.Info, "Step 1: Test Case Starts.");
        test.Log(Status.Pass, "Step 1: Test Case for Pass.");
        test.Log(Status.Fail, "Step 3: Test Case Failed.");

        _extentReport.Flush();
    }

private static string GetReportsClassLibraryPath() => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "......");
Thanks!

you can use ExtentV3HtmlReporter instead of ExtentHtmlReporter and it will be ok. it worked for me

How you manage to use ExtentV3HtmlReporter with .NET core? if I just change ExtentHtmlReporter for ExtentV3HtmlReporter I get error

@ak200275
Copy link

ak200275 commented Mar 12, 2020 via email

@sarad26
Copy link

sarad26 commented Jun 19, 2020

extent.AttachReporter(htmlReporter);

Not working For me, Can you tell me How to use that.

@elinasir
Copy link

Hi All,
I'm facing issue to generate Extent report or .netCore project. I have read above message and have installed ExtentReports.Core package, but the thing is at the teardown, extent.flush is not working, have error message"System.IO.FileNotFoundException : Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified."
and it's not generating html report. does anyone can help me out for this. thanks in advance.
My code looks like:
[OneTimeSetUp]
protected void Setup()
{
var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
var file = Path.Combine(solutionDir, "../..", "Reports", "ExtentReports", "ExtentReport.html");
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
var htmlReporter = new ExtentHtmlReporter(path);
_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);

    }
    [OneTimeTearDown]
    protected void TearDown()
    {

        _extent.Flush();

    }

[test]
public void test1(){
_test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
.....
...
}

@pawanbrn
Copy link

pawanbrn commented Jun 29, 2020

Hi All,
I'm facing issue to generate Extent report or .netCore project. I have read above message and have installed ExtentReports.Core package, but the thing is at the teardown, extent.flush is not working, have error message"System.IO.FileNotFoundException : Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified."
and it's not generating html report. does anyone can help me out for this. thanks in advance.
My code looks like:
[OneTimeSetUp]
protected void Setup()
{
var solutionDir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
var file = Path.Combine(solutionDir, "../..", "Reports", "ExtentReports", "ExtentReport.html");
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
var htmlReporter = new ExtentHtmlReporter(path);
_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);

    }
    [OneTimeTearDown]
    protected void TearDown()
    {

        _extent.Flush();

    }

[test]
public void test1(){
_test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
.....
...
}

This is fixed in latest dll of ExtentReports 4.1.0 beta1

@EBH2001
Copy link

EBH2001 commented Jul 31, 2021

Good Morning,

I run my selenium tests in a .NET Core project using Extent Reports 4.1.0 and my reports are generating successfully. However, the "Passed %" does not display if I have failed tests. It only displays if all the tests pass.

Any suggestions?
NoPassingTests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests