在表中Specflow使用的参数与场景语境 [英] Specflow use parameters in a table with a Scenario Context
问题描述
我在C#中使用Specflow建立与硒自动客户端浏览器测试。
I am using Specflow in C# to build automatic client side browser testing with Selenium.
这些试验的目的就是一个客户端进入模拟业务场景我们网站的特定页面,
,然后他被引导到正确的页面。
The goal of these tests is to simulate the business scenario where a client enters our website in specific pages, and then he is directed to the right page.
我想用一个场景上下文中的参数,
为例
I Want to use parameters inside a Scenario Context, for example:
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 |
注意:一步当我访问URL采用基地+网页+参数1 +参数2,创建网址基地/页/参数1 /参数2,去到这个网址。
Note: step "When I visit url" takes base+page+parameter1+parameter2, creates url "base/page/parameter1/parameter2" and goes to this URL.
的问题是,在步骤输入表我访问的URL被传递文本原样,而不修改在实施例部分的equivilent
The problem is that the input table in step "I visit url", is passing the text as-is, without modifying to the equivilent in the Examples section.
这意味着,上述的语法构建表中有数据的一排参数名:
It means that the table that the above syntax builds has a row with data the parameter names:
http://www.stackoverflow.com ,问题, questionNumber,questionName
http://www.stackoverflow.com, questions, questionNumber, questionName
而不是使用自己的价值:
Instead of using their value:
的 http://www.stackoverflow.com ,问题,123,specflow-Q1
http://www.stackoverflow.com, questions, 123 ,specflow-q1
你知道我怎么能正确使用?
Do you know how can I use it correctly?
推荐答案
这是不可能的混合数据表和情景轮廓。相反,我会重写你的情况如下:
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 |
里面的当我访问的URL的步骤定义你从passed-构造URL在表中的参数(这是你正在做什么)。
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.
这篇关于在表中Specflow使用的参数与场景语境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!