c# - SpecFlow 中的可选表

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

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

Then "User Info" area is displayed

而且我希望有可选的表格来检查该地区的一些其他信息(例如名字、姓氏、地址...)。

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

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

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

但是我在没有表格的情况下使用步骤时遇到了这个异常:

Parameter count mismatch! The binding method 'Example.ThenUserInfoAreaIsDisplayed()' should have 0 parameters

我也试过重载方法:

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

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

Parameter count mismatch! The binding method 'Example.ThenUserInfoAreaIsDisplayed()' should have 1 parameters

有什么想法吗?谢谢。

最佳答案

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

Then "User Info" area is displayed

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

关于c# - SpecFlow 中的可选表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40084649/

相关文章:

c# - 在虚拟化 WPF TreeView 中滚动非常不稳定

c# - 使用泛型时,如何确定 T 是否为负数?

c# - 在 If/else 与 ? 中分配委托(delegate):

c# - 单元测试中的模拟与 IoC 容器

c# - UIAutomation 和远程桌面连接

azure - 如何针对 Windows Azure SDK v1.4 运行编码的 UI 测试

unit-testing - MTM 编码 UI 测试手动执行 : "Recording Not Found"

c# - 在 WCF 中调试自定义服务主机工厂

tfs - 自动化测试和多重配置

javascript - 如何使用 WebdriverIO 返回一个新的有效页面对象?