Was*_*fa1 10 .net c# bdd specflow gherkin
我在C#中使用Specflow来使用Selenium构建自动客户端浏览器测试.
这些测试的目标是模拟客户在特定页面中进入我们网站的业务场景,然后将其定向到正确的页面.
我想在场景上下文中使用参数,例如:
When I visit url
| base | page | parameter1 | parameter2 |
| http://www.stackoverflow.com | questions | <questionNumber> | <questionName> |
Then browser contains test <questionNumber>
Examples:
| <questionNumber> | <questionName> |
| 123 | specflow-q1 |
| 456 | specflow-q2 |
| 789 | specflow-q3 |
Run Code Online (Sandbox Code Playgroud)
注意:步骤"当我访问url"时需要base + page + parameter1 + parameter2,创建url"base/page/parameter1/parameter2"并转到此URL.
问题是步骤"我访问url"中的输入表是按原样传递文本,而不修改为"示例"部分中的"等效".
这意味着上面语法构建的表有一行数据参数名称:
http://www.stackoverflow.com,问题,questionNumber,questionName
而不是使用他们的价值:
http: //www.stackoverflow.com,questions,123,specflow-q1
你知道我怎么能正确使用它?
Ben*_*ith 13
无法混合数据表和场景大纲.相反,我会按如下方式重写您的方案:
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 |
Run Code Online (Sandbox Code Playgroud)
在"当我访问URL"步骤定义中,您将根据传入的表参数构建URL(这是您当前正在执行的操作).
虽然"示例"部分中重复了"基础"和"问题"值,但很清楚看到究竟是在测试什么.非技术用户(例如,业务用户)也将能够容易地理解该测试试图实现的内容.
这现在是可能的(至少我是用 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; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17338 次 |
| 最近记录: |