I'm pretty new to Specflow and C#, so I'm facing an issue with specflow hooks. The problem is: when I use [BeforeScenario], the method is not even called while debugging. Removing these hooks and replacing it by [TestInitialize], it works perfectly. I searched here for solution in many questions, but I didn't find any problem besides something about private methods, which not seems to be my case.
I have 4 classes: Tests, Steps, PageObjects, and Hooks (which contains driver and hooks). 'Tests' class inherits from 'Steps', which inherits from 'PageObjects', which inherits from 'Hooks'. Every call is public and I'm writing down some code from 'Hooks' class:
namespace AutomationPractice.Helper
{
[Binding]
public class Hooks
{
public IWebDriver _driver;
[BeforeFeature]
public void BeforeScenario()
{
if (_driver == null)
{
_driver = new ChromeDriver();
}
else { throw new Exception("Couldn't initialize the driver"); }
}
[AfterFeature]
public void AfterScenario()
{
if (_driver != null)
{
_driver.Quit();
}
else throw new Exception("There was an error while trying to close the driver");
}
}
}
'PageObjects' class:
namespace AutomationPractice.PageObjects
{
[Binding]
public class GoogleSearchPageObjects : Hooks
{
public string goToGooglePage(string url)
{
return _driver.Url = url;
}
public IWebElement GetTxtSearch()
{
return _driver.FindElement(By.Name("q"));
}
public void fillTxtSearch(string search)
{
GetTxtSearch().SendKeys(search);
}
}
}
'Steps' class:
namespace AutomationPractice.Steps
{
[Binding]
public class GoogleSearchSteps : GoogleSearchPageObjects
{
[Given(@"I am on google home page")]
public void GivenIAmOnGoogleHomePage(string url)
{
goToGooglePage(url);
}
[When(@"I fill the '(.*)' field")]
public void WhenIFillTheField(string search)
{
fillTxtSearch(search);
}
Every class is rounded by [Binding] though.
Thanks in advance!
[Binding]fromHooksandGoogleSearchPageObjectsand run again - user1207289