【发布时间】:2013-12-12 00:53:59
【问题描述】:
这是我的小黄瓜:
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 |
这会生成以下步骤文件:
[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();
}
}
问题如下:
- 为用户名生成的正则表达式基于示例列中的第一个条目。这不是我想要的,因为并非所有示例都遵循这种模式。
- 方法名称使用示例列中的第一个条目(即 WhenLoginUsingUsernameValidXyz_ComAndPasswordPassword)。这很难阅读,如果示例表中的数据发生更改,则方法名称不再正确
- 参数的类型是 int。它们应该是字符串。
我希望步骤定义生成输出如下内容:
[When(@"Login using username (.*) and password (.*)")]
public void WhenLoginUsingUsernameAndPassword(string p0, string p1)
{
ScenarioContext.Current.Pending();
}
我错过了什么吗?有没有办法影响 SpecFlow 为场景大纲生成步骤方法的方式?如果没有,在不破坏我的更改背后的功能生成代码的情况下解决此问题的最佳方法是什么
【问题讨论】: