问题
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