问题
How to get tags from scenario into step definition in Ruby?
**@TAGS**
Scenario: Showing information of the scenario
When I execute any scenario
Now my step definition is this:
And(/^When I execute any scenario$/) do |page|
How to get tag = @TAGS in step definition..
end
回答1:
Not a direct solution, but hooks (Before, After, AfterStep, etc) can be set to run for specific tags, which allows you to set instance variables that are accessible in the scenario
Before('@my_tag') do # will only run if the test has @my_tag tag
@my_tag = true # This instance variable will be accessible in the test
end
You could also use the fact that Before
hooks get the scenario passed to them and use that to set an instance variable to the tag names
Before do |scenario|
@tags = scenario.source_tag_names # @tags instance variable accessible in test
end
来源:https://stackoverflow.com/questions/47438266/how-to-get-tag-in-step-definition-from-scenario-ruby