Specflow use parameters in a table with a Scenario Context

心不动则不痛 提交于 2019-12-03 11:58:00

It is not possible to mix data tables and scenario outlines. Instead I'd rewrite your scenario as follows:

When I visit the URL <base>/<page>/<questionNumber>/<questionName>
Then the browser contains test <questionNumber>

Examples: 
 | base                         | page      | questionNumber | questionName |
 | http://www.stackoverflow.com | questions | 123            | specflow-q1  |
 | http://www.stackoverflow.com | questions | 456            | specflow-q2  |
 | http://www.stackoverflow.com | questions | 789            | specflow-q3  |

Inside the "When I visit the URL" step definition you'd construct the URL from the passed-in table parameter (which is what you are doing currently).

Whilst "base" and "question" values are repeated in the "Examples" section, it is clear to see what exactly is being tested. A non-technical user (e.g. business user) will also be able to easily understand what this test is trying to achieve too.

This is now possible (at least I'm doing it with SpecFlow v2.0)

[When(@"When I visit url")]
public void WhenIVisitUrl(Table table)
{
  var url = table.CreateInstance<UrlDTO>();
}

public class UrlDTO{
  public string base { get;set; }
  public string page { get;set; }
  public string parameter1 { get;set; }
  public string parameter2 { get;set; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!