2014-12-01 41 views
0

我对BDD和C#都引用了新的内容,并且我已经在基本功能和步骤定义方面取得了一些成功。BDD Specflow - 场景大纲其中文本跨越多行

我现在试图写一个步骤def它声称在网页上的一些文本。问题是,它显示当文本跨越多行,它的HTML标记像这样:

<span> 
    Your username or password didn't match. Please check you've entered them correctly. 
    <br> 
    <br> 
    If you're not sure about your username (or not sure if you're registered), you can <a href="/MyAccount/ForgottenYourDetails/ForgottenUsername">check your username here</a>. You can then reset your password if you need to. 
</span> 

和我的特征文件是这样的:

Scenario Outline: Customer tries to login multiple times and on the 5th try locks their account 
Given a registered user with a username of 'username' 
    * has <x> failed login attempts 
    * is '<status>' 
    * I am on the login page 
When I enter 'username' and 'password' 
    * I click Login 
Then I will see the login '<error message>' 
Examples: 
    | x | status | error message| 
    | 0 | Unlocked | Your username or password didn't match. Please check you've entered them correctly. If you're not sure about your username (or not sure if you're registered), you can check your username here. You can then reset your password if you need to.       | 
    | 1 | Unlocked | Your username or password didn't match. Please check you've entered them correctly. If you're not sure about your username (or not sure if you're registered), you can check your username here. You can then reset your password if you need to.       | 
    | 2 | Unlocked | Your username or password didn't match. Please check you've entered them correctly. If you're not sure about your username (or not sure if you're registered), you can check your username here. You can then reset your password if you need to.       | 
    | 3 | Unlocked | Your username or password didn't match. Please check you've entered them correctly. If you're not sure about your username (or not sure if you're registered), you can check your username here. You can then reset your password if you need to.       | 
    | 4 | Unlocked | Your account is locked. Don't worry, this is simply a security measure to protect your personal information and ensure only you have access to your account. You can unlock your account yourself online by answering your security question and resetting your password. | 

我有步骤问题有是则执行步骤

Then I will see the login '<error message>' 

这背后步的步定义如下

[Then(@"I will see the login '(.*)'")] 
public void ThenIWillSeeTheLogin(string p0) 
{ 
    var actual = WebBrowser.Current.FindElement(By.Id("validationSummarycontainer")).Text; 
    Assert.AreEqual(p0, actual); 
} 

因为我要检查显示有换行符的文本,我试过几个选项:正如上面

  1. ,但声称从网页上的文字时,已用\ r \ n \ r \ n代替换行符,但不符合我的预期 - 如此失败
  2. 我试过在“正确”之间放置\ r \ n \ r \ n。和 “如果”,例如 “正常。\ r \ n \ r \ n如果”,然而,这会引发异常

NUnit.Framework.InconclusiveException是由用户代码未处理 的HResult = -2146233088 消息=找不到与一个或多个步骤匹配的步骤定义。使用系统的 ;使用TechTalk.SpecFlow的 ;

namespace MyNamespace 
{ 
    [Binding] 
    public class StepDefinitions 
    { 
     [Then(@"I will see the login '(.*)'t match\. Please check you've entered them correctly\.\\r\n\\r\nIf you'(.*)'re registered\), you can check your username here\. You can then reset your password if you need to\.'")] 
    public void ThenIWillSeeTheLoginTMatch_PleaseCheckYouVeEnteredThemCorrectly_R_R_IfYouReRegisteredYouCanCheckYourUsernameHere_YouCanThenResetYourPasswordIfYouNeedTo_(string p0, string p1) 
     { 
      ScenarioContext.Current.Pending(); 
     } 
    } 
} 

源= nunit.framework 堆栈跟踪: 在NUnit.Framework.Assert.Inconclusive(字符串消息,对象[]参数) 在lambda_method(封闭,字符串,对象[]) 在TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestInconclusive(字符串消息) 在TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestPending(字符串消息) 在TechTalk.SpecFlow.ErrorHandling.ErrorProvider.ThrowPendingError(testStatus testStatus,字符串消息) 在TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() 在TechTalk.SpecFlow.TestRunner.CollectScenarioErrors() 在MyBDD.OR_RegressionFeature.ScenarioCleanup()在d:\ DATA \ jonec34 \我的文档\的Visual Studio 2012 \项目\ MyDD \ MyBDD \ OR-Regression.feature.cs:line 0 at d:\ Data \ jonec34 \ My Documents \ Visual Studio 2012中MyBDD.OR_RegressionFeature.CustomerTriesToLoginMultipleTimesAndOnThe5ThTryLocksTheirAccount(String x,String status,String errorMessage,String [] exampleTags) \项目\ MyBDD \ MyBDD \ OR-回归。功能:行38 的InnerException:

我现在难倒不幸的是,如果有人可以帮助或提供其他建议,会是非常美妙的

在此先感谢

回答

1

如果这是我的我d结构我的HTML和我的测试略有不同。对于测试我的消息分为两个部分,主要的消息和这样的决议建议:

Scenario Outline: Customer tries to login multiple times and on the 5th try locks their account 
Given a registered user with a username of 'username' 
    * has <x> failed login attempts 
    * is '<status>' 
    * I am on the login page 
When I enter 'username' and 'password' 
    * I click Login 
Then I will see the message '<main error message>' 
And I will see the advice '<resolution advice>' 
Examples: 
    | x | status | main error message| resolution advice| 
    | 0 | Unlocked | Your username or password didn't match. Please check you've entered them correctly. |If you're not sure about your username (or not sure if you're registered), you can check your username here. You can then reset your password if you need to.       | 

这将允许您测试邮件中单独两个字符串,只是做一个包含元素。

除了这个我会改变HTML,所以每一段文字,是在自己的容器(跨度或股利或段落或者别的什么)所以每个可以分别找到,你可以在内容直接再搭配起来,并得到摆脱<br>

+0

谢谢@Sam持有人。不幸的是,我不控制HTML或其构建方式,但会给你的建议尝试将信息拆分出来。 – Chris 2014-12-02 09:53:08