IUn*_*own 5 c# bdd specflow gherkin
这是我的小黄瓜:
Scenario Outline: Login using valid email address
Given I have not logged into the current computer
And Username <username> and password <password> is a valid account
When I start the client
And Login using username <username> and password <password>
Then The client should navigate to first time screen
Examples:
| username | password |
| valid001@xyz.com | password001 |
| valid002 | password002 |
Run Code Online (Sandbox Code Playgroud)
这会生成以下步骤文件:
[Binding]
public class UserLoginSteps
{
[Given(@"I have not logged into the current computer")]
public void GivenIHaveNotLoggedIntoTheCurrentComputer()
{
ScenarioContext.Current.Pending();
}
[Given(@"Username valid(.*)@xyz\.com and password password(.*) is a valid account")]
public void GivenUsernameValidXyz_ComAndPasswordPasswordIsAValidAccount(int p0, int p1)
{
ScenarioContext.Current.Pending();
}
[When(@"I start the client")]
public void WhenIStartTheClient()
{
ScenarioContext.Current.Pending();
}
[When(@"Login using username valid(.*)@xyz\.com and password password(.*)")]
public void WhenLoginUsingUsernameValidXyz_ComAndPasswordPassword(int p0, int p1)
{
ScenarioContext.Current.Pending();
}
[Then(@"The client should navigate to first time screen")]
public void ThenTheClientShouldNavigateToFirstTimeScreen()
{
ScenarioContext.Current.Pending();
}
}
Run Code Online (Sandbox Code Playgroud)
问题如下:
我希望步骤定义生成输出如下:
[When(@"Login using username (.*) and password (.*)")]
public void WhenLoginUsingUsernameAndPassword(string p0, string p1)
{
ScenarioContext.Current.Pending();
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?有没有办法影响SpecFlow为场景大纲生成步骤方法的方式?如果没有,那么在没有功能生成代码的情况下解决我的更改,解决此问题的最佳方法是什么
简而言之,好消息。这些自动生成的绑定只是为了方便,不会自动重新生成。事实上,我一直都是自己亲手制作这些。
这意味着您可以去更改它们,而不必担心它们会被破坏:-)
SpecFlow 的工作原理是在每次编辑 *.feature 文件时自动生成 *.feature.cs 文件。这些永远不应该被编辑,但是如果你仔细查看它们,你会发现它们基本上从你的场景中获取 Give、When 和 Then 行,并将它们作为参数传递给它自己的内部方法。在幕后,SpecFlow 使用反射来查找所有具有属性的类[Binding],然后查看所有具有[Given],[When]或[Then]属性的类方法以查找正则表达式列表。最佳匹配的正则表达式标识要调用的方法。这就是为什么绑定通常被描述为全局的,并且不应该真正使用继承来构建(因为您最终会得到多个相同的正则表达式)。
回到您所拥有的生成的绑定,只有当 SpecFlow 的 VS 插件检测到您没有匹配的正则表达式并且您尝试导航到功能文件中的定义 (F12) 时,才会在编辑器中创建这些绑定。它们实际上是供您构建的占位符。