Created
February 28, 2015 17:13
-
-
Save johnmmoss/03e1c688de6257a448e6 to your computer and use it in GitHub Desktop.
Example Specflow feature hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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