关于Cucumber,这是一个棘手的问题:
Feature: Some feature
Background:
Given I am on the root page
Scenario Outline: Relevant flash messages should appear
When I fill in some_field with: <name>
Then I should see the text: <relevant_flash>
Examples:
| name | relevant_flash |
| Some name | Some message |
Scenario Outline: Irrelevant flash messages should not appear
When I fill in some_field with: <name>
Then I should not see the text: <irrelevant_flash>
Examples:
| name | irrelevant_flash |
| Some name | Some message |
我讨厌不得不重复:
When I fill in some_field with: <name>
但由于显而易见的原因,它不能只是移植到后台。或者可以吗?如果您有解决方法,请告诉我......
答案 0 :(得分:0)
通过将成功和失败的消息组合在一起,可以更好地组织您的场景大纲以避免重复。
Feature: Some feature
Background:
Given I am on the root page
Scenario Outline: Relevant flash messages should appear
When I fill in some_field with: <name>
Then I should see <relevant_message>
Examples:
| name | relevant_flash |
| Some name | Some message |
| Some irrelevant name | Irrelevant message |
| Name for blank msg | |
答案 1 :(得分:0)
好吧,我可以用这样的东西简化你的黄瓜:
Feature: Some feature
Scenario Outline: Relevant flash messages should appear
Given I am on the root page
When I fill in some_field with: <name>
Then I should see <message>
Examples:
| name | message |
| Some name | Relevant message |
| Some other name | Irrelevant message |
| Some another name | another flash message |
您注意到我已将Background:
取出,因为我们已将其覆盖在Scenario Outline:
上
我认为这个步骤会运行起来很简单,而且重复过多