asp.net-mvc – ASP.NET MVC,BDD,Specflow和WatiN:将应用程序置
我是BDD,Specflow和WatiN的新手.我想使用这些工具自动化我的ASP.NET MVC应用程序的验收测试.
我已经想出了如何基本上使用这些工具,并且我成功构建了我的第一个验收测试:登录到网站. 这是测试的小黄瓜: Feature: Log on to the web As a normal user I want to log on to the web site Scenario: Log on Given I am not logged in And I have entered my name in the username textbox And I have entered my password in the password textbox When I click on the login button Then I should be logged and redirected to home 现在,我想写一堆其他测试,它们都需要用户进行身份验证.例如: Feature: List the products As an authenticated user I want to list all the products Scenario: Get Products Given I am authenticated And I am on the products page When I click the GetProducts button Then I should get a list of products 让我烦恼的是,为了使这个测试独立于其他测试,我必须编写代码再次登录网站.这是要走的路吗?我怀疑. 我想知道是否有最佳实践可以用来测试这样的场景.我应该在同一个浏览器上打开浏览器并按特定顺序运行测试吗?或者我应该将MVC应用程序置于特定状态? 解决方法
为此,我们有一个特定的Given步骤,在Gherkin中看起来像这样:
Given I am signed in as user@domain.tld 如您所述,此步骤基本上重用其他步骤来登录用户.如果测试用户具有非默认测试密码,我们还会有一个带有密码的“重载”: Given I am signed in as user@domain.tld using password "<Password>" [Binding] public class SignInSteps { [Given(@"I am signed in as (.*)")] public void SignIn(string email) { SignInWithSpecialPassword(email,"asdfasdf"); } [Given(@"I am signed in as (.*) using password ""(.*)""")] public void SignInWithSpecialPassword(string email,string password) { var nav = new NavigationSteps(); var button = new ButtonSteps(); var text = new TextFieldSteps(); var link = new LinkSteps(); nav.GoToPage(SignOutPage.TitleText); nav.GoToPage(SignInPage.TitleText); nav.SeePage(SignInPage.TitleText); text.TypeIntoTextField(email,SignInPage.EmailAddressLabel); text.TypeIntoTextField(password,SignInPage.PasswordLabel); button.ClickLabeledSubmitButton(SignInPage.SubmitButtonLabel); nav.SeePage(MyHomePage.TitleText); link.SeeLinkWithText("Sign Out"); } } 我认为这是最好的方法,因为您不能保证所有测试都按特定顺序运行. 您也可以使用SpecFlow标记执行此操作,并使该标记执行BeforeScenario.这可能看起来像这样: Feature: List the products As an authenticated user I want to list all the products @GivenIAmAuthenticated Scenario: Get Products Given I am on the products page When I click the GetProducts button Then I should get a list of products [BeforeScenario("GivenIAmAuthenticated")] public void AuthenticateUser() { // code to sign on the user using Watin,or by reusing step methods }
登录用户时,不是需要将MVC应用程序置于特定状态,而是需要将其置于特定状态的浏览器 – 即编写身份验证cookie.鉴于auth cookie已加密,我不确定您是否可以这样做.我总是发现让SF在每个场景开始时通过身份验证步骤更容易. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- razor – 没有布局参考的ASP.NET默认MVC4应用程序内容页面?
- ASP.NET Identity简介及简单使用
- asp.net-mvc – 如何在使用Html.BeginForm时使用锚标记进行
- 从ASP.NET MVC应用程序中的Amazon SES发送电子邮件
- asp.net – 最小长度的文本框验证器
- asp.net-core – 从与xproj相同的解决方案引用csproj
- asp.net – 前端头还是后端?
- asp.net – EF更新记录属性后在SaveChanges()上抛出NullRef
- 限制并发或不限制并发? (在单个ASP.NET请求中)
- 如何保持我的ASP.NET应用程序始终“活着”,如果它是一个坏主
- asp.net-mvc – Bootstrap模式表单在提交后不会关
- asp.net-mvc – 发布ASP.NET MVC 3 Html.TextAre
- asp.net-mvc – Chrome 27中SignalR和跨域请求的
- asp.net-mvc – 重定向到操作,需要传递数据
- asp.net – IIS7.5中x64进程的内存限制
- 反射及LINQ结果集转换dataTable并序列化 将Da
- ASP.NET错误处理
- 如何将组名应用于asp.net中的HTML单选按钮?
- asp.net-web-api – ASP.NET Web API:如何在Web
- asp.net – “线程被中止了什么”. ‘SNIReadSyn