I am working on .NetCore App 2.1 project and I created some selenium scripts in C# for that project with NUnit framework(in MacOS). I am able to execute it successfully. However, I am not able to generate report using Extent Report 3.1.3(Also, Tried 2.41.x), As I am getting warning that It has been restored with .NETFramework 4.6.1, But not with .NetCore app with Project Target framework, while compilinh. When I execute it, It threw me lots of exception. I resolved one by one, by adding Nuget packages. Finally, I am into the following exception, from which I am not able to move further.
TearDown failed for test fixture RBAutomationDemo.UnitTest1
TearDown : System.TypeLoadException : Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
--TearDown
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.WithWriter(Action`1 withWriter)
at AventStack.ExtentReports.Reporter.ExtentHtmlReporter.Flush()
at AventStack.ExtentReports.Model.Report.<>c.<NotifyReporters>b__29_1(IExtentReporter x)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at AventStack.ExtentReports.Model.Report.NotifyReporters()
at AventStack.ExtentReports.Model.Report.Flush()
at AventStack.ExtentReports.ExtentReports.Flush()
at RBAutomationDemo.UnitTest1.OneTimeTearDown()`
Please help me on this.
Code I used:
using System;
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using LocatorsFile;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
namespace RBAutomationDemo
{
[SetUpFixture]
public abstract class Base
{
protected ExtentReports _extent;
protected new ExtentTest _test;
[OneTimeSetUp]
protected void ReportSetup()
{
var dir = TestContext.CurrentContext.TestDirectory + "\\";
var fileName = this.GetType().ToString() + ".html";
System.Console.WriteLine(fileName);
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(dir + fileName);
_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);
}
[OneTimeTearDown]
protected void ReportTearDown()
{
_extent.Flush();
}
[SetUp]
public void BeforeTest()
{
_test = _extent.CreateTest(TestContext.CurrentContext.Test.Name);
Initialize();
}
[Test]
public void Testmethod1()
{
_test = extent.CreateTest("Checking Total workbooks count");
try
{
_test.Pass("Assertion passed");
_test.Log(Status.Pass, "Pass");
}
catch
{
_test.Fail("Assertion failed");
_test.Log(Status.Fail, "Fail");
throw;
}
}
[TearDown]
public void AfterTest()
{
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.Flush();
DoTearDown();
}
}
}
Please see below:
EDIT:
Version 4 sources are now available, see here
As per the project owner (@anshooarora): "I am happy to add support for .NET core but I am still a little skeptical how well supported the required packages are. I have also been out of touch so I would probably need some help to roll this out."