I have following problem. I need to register my webdriver instance inside of the specflow BeforeFeature method using context injection, but this method must be static. I have an error that my global container object have to be static. Is there any way to use this context injection in static method?
Here is my code:
[Binding]
public class SpecflowHooks
{
private readonly IObjectContainer container;
public SpecflowHooks(IObjectContainer container)
{
this.container = container;
}
[BeforeFeature]
public static void OneTime()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--ignore-ssl-errors=yes");
options.AddArgument("--ignore-certificate-errors");
ChromeDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
container.RegisterInstanceAs<IWebDriver>(driver);
}
[BeforeScenario]
public void SetUp()
{
}
[AfterScenario]
public void TearDown()
{
}
[AfterFeature]
public static void FeatureTearDown()
{
IWebDriver driver = container.Resolve<IWebDriver>();
driver.Close();
driver.Dispose();
}
}