Cucumber - Is it possible to share a table between Scenarios?

南笙酒味 提交于 2019-12-08 07:04:47

问题


Does anyone know its its possible to define a table once in a .feature file & then access it from multiple scenarios? I'm not chaining scenarios but many of them do need to pass tables with the same data to their step definitions - also for this reason examples won't really do what I need here.

Thanks!


回答1:


One possible solution is to tag all your scenarious where you need a table:

@given_have_table
Scenario: test
  Then I am happy

Then bind Before hook to this tag and call step that declares your table from within Before hook definition:

Before("@given_have_table") do
  steps Q%{
  Given I have the following table:
    | a | b |
    | 1 | 2 |
  }
end

Alternative approach is to construct required table in tagged Before hook without calling step:

Before("@given_have_table") do
  @tbl = { :a => 1, :b => 2 }
end


来源:https://stackoverflow.com/questions/8899053/cucumber-is-it-possible-to-share-a-table-between-scenarios

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