extentreports-csharp
extentreports-csharp copied to clipboard
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot perform runtime binding on a null reference'
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<Feature>(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;
}
@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.
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