【发布时间】:2018-11-27 20:08:16
【问题描述】:
我在两个不同的功能文件中有两个场景,但两个场景都测试搜索功能,但在我页面的不同部分。 我的场景看起来像这样:
Scenario Outline: Search items from QuickSearch
Given that the following items
| id | title |
| 1 | Item1 |
| 2 | Item2 |
When I search for <criteria> in this search
Then I should get <result>
And I should not get <excluded>
Examples:
|criteria|result | excluded |
| 1 | 1 | 2 |
| 2 | 2 | 1 |
和:
Scenario Outline: Using a filter
Given that I have the following things:
|id |name |
|1 | thing1 |
|2 | thing2 |
When I use the <filter> filled with <criteria>
Then I should obtain these <results>
And I should not obtain these <exclusions>
Examples:
|filter |criteria |results |exclusions |
|name |thing |1,2 | |
|id |1 |1 |2 |
正如您在第二个场景中所说的那样,我已经更改了 get 一词,以便为这两个场景编写单独的步骤。 我需要两个不同步骤的唯一原因是因为 2 个不同场景中的 id 映射到不同的名称(不,我不能对两者使用相同的名称,并且不想在第二个中从 id 3 开始)
所以我正在考虑这两种场景的通用步骤(至少在涉及到 then 步骤时),我想要一个哈希映射 id 和 name 一起进行验证,但我希望哈希是根据调用步骤的场景而有所不同。
那么,cucumber + capybara 有没有办法可以分辨出哪个场景叫做 step?
【问题讨论】:
-
值得注意的是 things != items.