Last active
August 29, 2015 14:01
-
-
Save hatelove/d4753a9e02d3080eac3f to your computer and use it in GitHub Desktop.
Login Feature & Steps
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
Feature: Login | |
In order to 避免非法使用者使用系統 | |
As a 系統管理者 | |
I want to be 檢查帳號密碼是否合法 | |
Scenario: 登入成功,導到首頁 | |
Given Login的頁面 | |
When 在帳號輸入"joey" | |
And 在密碼輸入"1234" | |
And 按下登入 | |
Then 導到首頁 | |
Scenario: 登入失敗,顯示錯誤訊息 | |
Given Login的頁面 | |
When 在帳號輸入"joey" | |
And 在密碼輸入"abc" | |
And 按下登入 | |
Then 顯示"帳號或密碼有誤" |
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
using FluentAutomation; | |
using TechTalk.SpecFlow; | |
namespace TddWithAspMvc.Tests.features | |
{ | |
[Binding] | |
[Scope(Feature = "Login")] | |
public class LoginSteps : FluentTest | |
{ | |
public LoginSteps() | |
{ | |
SeleniumWebDriver.Bootstrap( | |
SeleniumWebDriver.Browser.Chrome, | |
SeleniumWebDriver.Browser.Firefox, | |
SeleniumWebDriver.Browser.InternetExplorer | |
); | |
FluentAutomation.FluentSettings.Current.ScreenshotPath = @"C:\excel"; | |
} | |
//private IWebDriver driver; | |
//private StringBuilder verificationErrors; | |
private string baseURL; | |
//private bool acceptNextAlert = true; | |
[BeforeScenario] | |
public void BeforeScenario() | |
{ | |
//driver = new FirefoxDriver(); | |
baseURL = "http://localhost:6425/"; | |
//verificationErrors = new StringBuilder(); | |
} | |
[AfterScenario] | |
public void AfterScenario() | |
{ | |
//try | |
//{ | |
// driver.Quit(); | |
//} | |
//catch (Exception) | |
//{ | |
// // Ignore errors if unable to close the browser | |
//} | |
//Assert.AreEqual("", verificationErrors.ToString()); | |
} | |
[Given(@"Login的頁面")] | |
public void GivenLogin的頁面() | |
{ | |
//driver.Navigate().GoToUrl(baseURL + "/login"); | |
I.Open(baseURL + "/login"); | |
} | |
[When(@"在帳號輸入""(.*)""")] | |
public void When在帳號輸入(string id) | |
{ | |
//driver.FindElement(By.Id("id")).Clear(); | |
//driver.FindElement(By.Id("id")).SendKeys(id); | |
I.Enter(id).In("#id"); | |
} | |
[When(@"在密碼輸入""(.*)""")] | |
public void When在密碼輸入(string password) | |
{ | |
//driver.FindElement(By.Id("password")).Clear(); | |
//driver.FindElement(By.Id("password")).SendKeys(password); | |
I.Enter(password).In("#password"); | |
} | |
[When(@"按下登入")] | |
public void When按下登入() | |
{ | |
//driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click(); | |
I.Click("input[type=\"submit\"]"); | |
} | |
[Then(@"顯示""(.*)""")] | |
public void Then顯示(string message) | |
{ | |
I.TakeScreenshot("驗證message"); | |
//Assert.AreEqual(message, driver.FindElement(By.Id("message")).Text); | |
I.Assert.Text(message).In("#message"); | |
} | |
[Then(@"導到首頁")] | |
public void Then導到首頁() | |
{ | |
//Assert.AreEqual("http://localhost:6425/", driver.Url); | |
I.Assert.Url("http://localhost:6425/"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment