Scenario hooks only valid on scenario outlines?

十年热恋 提交于 2019-12-11 17:08:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!