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

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot perform runtime binding on a null reference' #95

Open dhinaraj opened 6 years ago

dhinaraj commented 6 years ago

Trying to use Extent Report (3.0.2) for Specflow BDD test report and extent.flush() method results in error mentioned in title

Code:

private static ExtentReports extent; private static ExtentTest FeatureTest; private static ExtentTest ScenarioTest; private static ExtentTest StepTest; private static DateTime reportFolderNameWithDateAndTime = new DateTime(); private static string reportDateTimeString = reportFolderNameWithDateAndTime.ToString(); private static string reportLocation = @"C:\Users\sesa473389\Desktop\"; private static ExtentHtmlReporter htmlReporter;
public static void HtmlReportBeforeFeature() { extent = GetExtent(); FeatureTest = extent.CreateTest(FeatureContext.Current.FeatureInfo.Title); }

    public static void HtmlReportBeforeScenario()
    {
        ScenarioTest = FeatureTest.CreateNode<Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
    }

    public static void HtmlReportAfterEachScenarioStep()
    {
        if (ScenarioContext.Current.TestError != null)
        {
            var error = ScenarioContext.Current.TestError;
            var errormessage = "<pre>" + error.Message + "</pre>";
            //Add capture screen shot line here
            StepTest = ScenarioTest.CreateNode(ScenarioContext.Current.StepContext.StepInfo.StepDefinitionType.ToString(), ScenarioContext.Current.StepContext.StepInfo.Text).Fail("Fail");

        }

        else
        {
            StepTest = ScenarioTest.CreateNode(ScenarioContext.Current.StepContext.StepInfo.StepDefinitionType.ToString(), ScenarioContext.Current.StepContext.StepInfo.Text).Pass("Pass");

        }
    }

    public static void HtmlReportAfterFeature()
    {
        extent.Flush();
    }

    private static ExtentReports GetExtent()
    {
        if (extent != null)
            return extent; //avoid creating new instance of html file
        extent = new ExtentReports();
        extent.AttachReporter(getHtmlReporter());
        return extent;
    }

    private static ExtentHtmlReporter getHtmlReporter()
    {

        htmlReporter = new ExtentHtmlReporter(reportLocation + "Report.html");

        // make the charts visible on report open
        htmlReporter.Configuration().ChartVisibilityOnOpen = true;

        htmlReporter.Configuration().DocumentTitle = "Test Extent Report";
        htmlReporter.Configuration().ReportName = "Test Cycle";
        return htmlReporter;
    }
chakraborty-rupam commented 6 years ago

@dhinaraj - This doesn't look to be an Extent Report issue. Specflow has its own Binding at different levels like - Step Definitions, Hooks etc. It appears you might have an issue there, can you please remove Extent reports code or comment them out and rebuild the solution? My 2 cents is you will probably end up seeing the same exception again.

Beni-Landmark commented 6 years ago

i had the same issue and this is what i did and it worked for me i used the createnode with angle brackets and typed in Scenario into the angle brackets