BDD 规范流 - 文本跨多行的方案大纲
本文关键字:方案 范流 文本 BDD | 更新日期: 2023-09-27 18:32:44
我是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 步骤
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);
}
由于我要检查的文本以换行符显示,因此我尝试了几个选项:
- 如上所述,但是当断言网页中的文本有''r'''r'代替换行符时,但不在我的预期中 - 所以失败 我尝试将''r'''r'放在"正确">
- 和"如果"之间,例如"正确"。
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();
}
}
}
Source=nunit.framework 堆栈跟踪: at NUnit.Framework.Assert.Inconclusive(String message, Object[] args( at lambda_method(闭包、字符串、对象[] ( at TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestInconconclusive(String message( at TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestPending(String message( at TechTalk.SpecFlow.ErrorHandling.ErrorProvider.ThrowPendingError(TestStatus testStatus, String message( at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep(( at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors(( at MyBDD.OR_RegressionFeature.ScenarioCleanup(( in d:''Data''jonec34''My Documents''Visual Studio 2012''Projects''MyBDD''MyBDD''OR-Regression.feature.cs:line 0 at MyBDD.OR_RegressionFeature.CustomerTriesToLoginMultipleTimesAndOnThe5ThTryLocksTheirAccount(String x, String status, String errorMessage, String[] exampleTags( in d:''Data''jonec34''My Documents''Visual Studio 2012''Projects''MyBDD''MyBDD''OR-Regression.feature:line 38 内部异常:
不幸的是,我现在被难住了,如果有人可以帮助或提供其他建议,那就太棒了
提前致谢
如果这是我,我会稍微不同地构建我的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,以便每段文本都在自己的容器中(跨度或div 或段落或其他任何内容(,以便可以单独找到每个文本,然后您可以直接匹配内容并摆脱<br>