I am receiving NullReferenceException on CleanUp() method. The below code is from SpecflowHooks.cs
Driver code in SpecflowHooks
public static ChromeDriver driver { get; set; }
[BeforeFeature]
public static void OneTime()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--ignore-ssl-errors=yes");
options.AddArgument("--ignore-certificate-errors");
string Path = "D:/repos/Hoogly/Drivers/";
driver = new ChromeDriver(Path);
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
}
private readonly IObjectContainer container;
public SpecflowHooks(IObjectContainer container)
{
this.container = container;
}
[BeforeScenario]
public void Setup()
{
container.RegisterInstanceAs(driver);
}
[AfterScenario]
public void CleanUp()
{
container.Resolve<IWebDriver>();
driver.Close();
driver.Dispose();
}
While Debugging I noticed that the Container is blank when Cleanup() method is executed. But I am not clear as to why that is getting blank even after the Register Instance in Setup(). I am using Specflow and Selenium Webdriver I am not sure if this is the optimal way to manage drivers.