问题
We're using Cucumber and Selenium with Ruby. After reading the documentation on hooks I've tried my hand at setting a few tags to set (for example) some environment variables.
Here's a contrived example that demonstrates the problem.
When I establish a Before
hook like so:
Before('@tag1', '@tag2') do
puts "in the before hook!"
end
It'll take effect with a scenario defined like so:
@tag1 @tag2
Scenario Outline: This is a test scenario
Given I run my first step for "<user>"
Then I complete my test
@firstrun
Scenarios:
|user|
|fred|
@secondrun
Scenarios:
|user|
|barney|
..however if I move @tag1
and @tag2
to the individual scenarios and not the scenario outline, the hook is never called, for instance:
@secondrun @tag1 @tag2
Scenarios:
|user|
|barney|
Is it possible to 'hook in' individual scenarios, or just the outlines?
回答1:
Typically with scenario outlines the table of values you're testing is tied to that, not separate scenarios.
E.g
ScenarioOutline
Given I am on gmails website
When I login as <user> with <password>
Then I am able to view my primary inbox
Example:
| user | password |
| Fred | xd13#%& |
来源:https://stackoverflow.com/questions/29420474/scenario-hooks-only-valid-on-scenario-outlines