我引用了BDD和C#的新内容,并且我在基本功能和步骤定义方面取得了一些成功。
我现在正在尝试编写一个步骤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);
}
因为我要查看的文字会显示换行符,所以我尝试了几个选项:
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(String message,Object [] args) 在lambda_method(Closure,String,Object []) at TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestInconclusive(String message) at TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestPending(String message) 在TechTalk.SpecFlow.ErrorHandling.ErrorProvider.ThrowPendingError(TestStatus testStatus,String message) 在TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep() 在TechTalk.SpecFlow.TestRunner.CollectScenarioErrors() 在d:\ Data \ jonec34 \ My Documents \ Visual Studio 2012 \ Projects \ MyBDD \ MyBDD \ OR-Regression.feature.cs中的MyBDD.OR_RegressionFeature.ScenarioCleanup():第0行 at MyBDD.OR_RegressionFeature.CustomerTriesToLoginMultipleTimesAndOnThe5ThTryLocksTheirAccount(String x,String status,String errorMessage,String [] exampleTags)在d:\ Data \ jonec34 \ My Documents \ Visual Studio 2012 \ Projects \ MyBDD \ MyBDD \ OR-Regression.feature:第38行 InnerException:
我很遗憾,如果有人可以提供帮助或提供其他非常棒的建议
提前致谢
答案 0 :(得分:1)
如果这是我,我将构建我的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,因此每段文本都在自己的容器中(span或div或段落或其他),所以每个都可以单独找到,然后你可以直接匹配内容并摆脱<br>
的