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

Error with ExtentReports Flush and Razor #228

Open
alicemacdonald20 opened this issue Aug 21, 2024 · 0 comments
Open

Error with ExtentReports Flush and Razor #228

alicemacdonald20 opened this issue Aug 21, 2024 · 0 comments

Comments

@alicemacdonald20
Copy link

alicemacdonald20 commented Aug 21, 2024

I have receiving the below error when I run my test. It is complaining about the TearDown FlushReport function:

TearDown : System.TypeLoadException : Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=6.0.33.0

I understand it may be caused by incompatible package versions but I am new to coding and don’t know how I know what is or isn’t compatible?

These are my nuget package versions:

<PackageReference Include="ExtentReports" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.33" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.46.0" />
<PackageReference Include="Microsoft.Playwright.TestAdapter" Version="1.46.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">

And my code (ExtentReport.cs):

public static void InitialiseReport()
{
    string dir = AppDomain.CurrentDomain.BaseDirectory;
    string testReportPath = dir.Replace("bin\\Debug\\net8.0", "TestResults " + DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss"));
    string reportName = "Test Report" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(testReportPath);
    htmlReporter.Config.DocumentTitle = reportName;
    _extentReports = new ExtentReports();
    _extentReports.AttachReporter(htmlReporter);
}

public static void FlushReport()
{
    _extentReports.Flush();
}

And the test file TearDown that utilises this file, this is where the error is occurring:

 [TearDown]
 public void TearDown()
 {
     var status = TestContext.CurrentContext.Result.Outcome.Status;
     var stackTrace = TestContext.CurrentContext.Result.StackTrace;
     var errorMessage = TestContext.CurrentContext.Result.Message;

     switch(status)
     {
         case TestStatus.Failed:
             ExtentReport._test.Log(Status.Fail, "Test failed: " + errorMessage);
             ExtentReport._test.Log(Status.Fail, "Stack Trace: " + stackTrace);
             break;
         case TestStatus.Inconclusive:
             ExtentReport._test.Log(Status.Warning, "Test inconclusive");
             break;
         case TestStatus.Skipped:
             ExtentReport._test.Log(Status.Skip, "Test skipped");
             break;
         default:
             ExtentReport._test.Log(Status.Pass, "Test passed");
             break;
     }

     ExtentReport.FlushReport();
 }

 [OneTimeTearDown]
 public void OneTimeTearDown()
 {
     ExtentReport.FlushReport();
     _driver.Dispose();
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant