Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Last active August 29, 2015 14:16
Show Gist options
  • Save johnmmoss/311700a22e4b63df90ed to your computer and use it in GitHub Desktop.
Save johnmmoss/311700a22e4b63df90ed to your computer and use it in GitHub Desktop.
Example Specflow steps
[Binding]
public class UserAccountSteps
{
[Given(@"I am on the register page")]
public void GivenIAmOnTheRegisterPage()
{
var homePage = ScenarioContext.Current.Get<HomePage>();
var registerPage = homePage.GoToRegisterPage();
ScenarioContext.Current.Set(registerPage);
}
[Given(@"I have entered a Username of '(.*)' and a password of '(.*)'")]
public void GivenIHaveEnteredAUsernameOfAndAPasswordOf(string username, string password)
{
var registerPage = ScenarioContext.Current.Get<RegisterPage>();
registerPage.EnterDetails(username, password);
}
[When(@"I press register")]
public void WhenIPressRegister()
{
var registerPage = ScenarioContext.Current.Get<RegisterPage>();
registerPage.ClickRegister();
}
[Then(@"a new account is created with a username of a Username of '(.*)'")]
public void ThenANewAccountIsCreatedWithAUsernameOfAUsernameOf(string username)
{
using (var context = new SpecflowTestContext())
{
var allUserProfiles = context.UserProfiles.ToList();
Assert.That(allUserProfiles.Count, Is.EqualTo(1));
Assert.That(allUserProfiles.First().UserName, Is.EqualTo(username));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment