extent-framework / extentreports-csharp

Extent Reporting Library, .NET
http://extentreports.com
Apache License 2.0
50 stars 40 forks source link

Error: AventStack.ExtentReports.ExtentReports.GherkinDialect.get #87

Closed nukalaamar closed 4 years ago

nukalaamar commented 4 years ago

Hi Team, Environment : .Net, Visual Studio 2019 When I debug my code, I am getting below error at extent.flush().

Error: The Target process exited with code 2147943401 while evaluating the function ' AventStack.ExtentReports.ExtentReports.GherkinDialect.get'

Please advise. Thanks

anshooarora commented 4 years ago

@nukalaamar Please share the code that I can use to reproduce this issue.

nukalaamar commented 4 years ago

Hi Anshoo, Thanks for the reply. Please see below code. public class Hooks { private readonly BrowserContext browserContext; private static AventStack.ExtentReports.ExtentReports extent; private static ExtentHtmlReporter _extentHtmlReporter; private static ExtentTest _feature; private static ExtentTest _scenario; private static ScenarioContext _scenarioContext; private static FeatureContext _featureContext;

    public Hooks(BrowserContext browserContext)
    {
        this.browserContext = browserContext;
    }

    [BeforeTestRun]
    public static void BeforeTestRun()
    {
        _extentHtmlReporter = new ExtentHtmlReporter(@"E:\log");
        extent = new AventStack.ExtentReports.ExtentReports();          
        extent.AttachReporter(_extentHtmlReporter);
    }
    [BeforeFeature]
    public static void BeforeFeatureStart(FeatureContext featureContext)
    {
        if (null != featureContext)
        {
            //_featureContext = featureContext;
            _feature = extent.CreateTest<Feature>(featureContext.FeatureInfo.Title, featureContext.FeatureInfo.Description);
        }
    }

    [BeforeScenario]
    public void BeforeScenarioStart(ScenarioContext scenarioContext)
    {
        browserContext.Initialize();
        if (null != scenarioContext)
        {
            _scenarioContext = scenarioContext;
            _scenario = _feature.CreateNode<Scenario>(scenarioContext.ScenarioInfo.Title, scenarioContext.ScenarioInfo.Description);
        }
    }
    [AfterStep]
    public void AfterEachStep()
    {
        ScenarioBlock scenarioBlock = _scenarioContext.CurrentScenarioBlock;

        switch (scenarioBlock)
        {
            case ScenarioBlock.Given:

                CreateNode<Given>();
                break;
            case ScenarioBlock.When:
                //if (_scenarioContext.TestError != null)
                //{
                //    _scenario.CreateNode<When>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.Message + "\n" + _scenarioContext.TestError.StackTrace);
                //}

                CreateNode<When>();
                break;
            case ScenarioBlock.Then:
                CreateNode<Then>();
                break;

            default:

                CreateNode<And>();
                break;

        }

    }
    public void CreateNode<T>() where T : IGherkinFormatterModel

    {
        if (_scenarioContext.TestError != null)
        {             
            _scenario.CreateNode<T>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.Message + "\n" + _scenarioContext.TestError.StackTrace);

        }
        else
        {
            _scenario.CreateNode<T>(_scenarioContext.StepContext.StepInfo.Text).Pass("");
        }

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

    [BeforeFeature("Tag1")]
    public static void BeforeFeature(FeatureContext featureContext)
    {
        Console.WriteLine("BeforeFeature Hook");
    }

    [AfterFeature("Tag1")]
    public static void AfterFeature()
    {
        Console.WriteLine("AfterFeature Hook");
    }      

    [BeforeScenario]
    public static void BeforeScenarioContextInjection(FeatureContext featureContext, ScenarioContext scenarioContext)
    {
        _featureContext = featureContext;
        _scenarioContext = scenarioContext;
    }

    [AfterScenario]
    public void AfterScenario()
    {
        Console.WriteLine("AfterScenario Hook");
        browserContext.Quit();
    }
}

}

nukalaamar commented 4 years ago

I have tried again today and I am getting below exception. Please advise. Exception: 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.'

anshooarora commented 4 years ago

Thanks, which nuget package are you using? .Net Framework or .Net Core/Standard?

nukalaamar commented 4 years ago

Hi I am using .Net Core . TargetFramework: netcoreapp3.1

Nuget packages as below: Nuget_Extent

Thanks