You cannot access this information directly from the step definition. If you need information, you will need to capture it in time to hook.
Cucumber v3 +
The following will capture the function name, script / schema name, and tag list before capturing begins. Please note that this is a solution for Cucumber v3.0 +. For earlier versions, see End of answer.
Before do |scenario|
As an example, a function file:
@feature_tag Feature: Feature description @regular_scenario_tag Scenario: Scenario description Given scenario details @outline_tag Scenario Outline: Outline description Given scenario details Examples: |num_1 | num_2 | result | | 1 | 1 | 2 |
In increments defined as:
Given /scenario details/ do p @feature_name p @scenario_name p @scenario_tags end
They will give the results:
"Feature description" "Scenario description" ["@feature_tag", "@regular_scenario_tag"] "Feature description" "Outline description, Examples (#1)" ["@feature_tag", "@outline_tag"]
You can then check the @scenario_name or @scenario_tags name for your conditional logic.
Cucumber v2
For cucumber v2, the required hook is more complex:
Before do |scenario|
The output is slightly different:
"Feature description" "Scenario description" ["@regular_scenario_tag", "@feature_tag"] "Feature description" "Outline description" ["@outline_tag", "@feature_tag"]
source share