【问题标题】:Optional table in SpecFlowSpecFlow 中的可选表
【发布时间】:2017-02-26 08:01:58
【问题描述】:

我在 SpecFlow 中有一个步骤来检查是否显示了某些区域(例如用户信息)。

Then "User Info" area is displayed

并且我想为这一步提供可选表格,检查该区域中的一些其他信息(例如名字、姓氏、地址...)。

Then "User Info" area is displayed
| Surname |
| Smith   |

我尝试创建一个带有可选参数的方法:

public void ThenUserInfoAreaIsDisplayed(Table table = null)
{
  ...
}

但是在使用没有表格的步骤时出现了这个异常:

参数计数不匹配!绑定方法'Example.ThenUserInfoAreaIsDisplayed()'应该有0个参数

我也尝试过重载方法:

public void ThenUserInfoAreaIsDisplayed()
{
  ...
}
public void ThenUserInfoAreaIsDisplayed(Table table)
{
  ...
}

在这种情况下,我得到以下异常:

参数计数不匹配!绑定方法'Example.ThenUserInfoAreaIsDisplayed()'应该有1个参数

有什么想法吗?谢谢。

【问题讨论】:

  • 您能否在步骤方法中包含[Then("")] 属性

标签: c# automated-tests coded-ui-tests specflow gherkin


【解决方案1】:

我认为这不可能完全如你所愿。您可以使用稍微扩展/修改的措辞为带有表格的版本添加另一个步骤定义:

Then "User Info" area is displayed

Then "User Info" area is displayed with this information:
| Surname |
| Smith   |

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-16
    • 2022-01-12
    • 2019-12-09
    • 2011-07-10
    相关资源
    最近更新 更多