Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Created February 28, 2015 17:13
Show Gist options
  • Save johnmmoss/03e1c688de6257a448e6 to your computer and use it in GitHub Desktop.
Save johnmmoss/03e1c688de6257a448e6 to your computer and use it in GitHub Desktop.
Example Specflow feature hooks
[BeforeFeature()]
public static void BeforeFeature() // must be static
{
// Create the webdriver and store it in the feature context
IWebDriver driver = new FirefoxDriver();
FeatureContext.Current.Set(driver);
driver.Navigate().GoToUrl(Url);
// Empty the database ready for the tests
using (var context = new SpecflowTestContext())
{
context.Database.ExecuteSqlCommand("DELETE FROM UserProfile");
}
}
[AfterFeature]
public static void AfterFeature()
{
// Clear up the webdriver
var webDriver = FeatureContext.Current.Get<IWebDriver>();
webDriver.Quit();
webDriver.Dispose();
}
[BeforeScenario]
public void BeforeScenario()
{
// At the begining of the scenario, we are on the homepage
var webDriver = FeatureContext.Current.Get<IWebDriver>();
var homePage = new HomePage(webDriver);
ScenarioContext.Current.Set<HomePage>(homePage);
}
[AfterScenario]
public void AfterScenario()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment