Andrei Botalov
Andrei Botalov

Reputation: 21096

Can I access feature name in scenario hook?

I'd want to get feature name in scenario hook. How can I get it?

What information besides scenario name and exception message is available in scenario hook?

Upvotes: 1

Views: 1222

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

You can get the feature name by accessing the feature from the scenario object:

Before do |scenario|
    case scenario
        when Cucumber::Ast::Scenario
            p scenario.feature.title
        when Cucumber::Ast::OutlineTable::ExampleRow
            p scenario.scenario_outline.feature.title
    end
end

Note that you have to handle scenarios vs scenario outlines differently.

For other information that is available about the scenario, the best bet is to view the documentation - see http://rdoc.info/gems/cucumber/Cucumber/Ast/Scenario.

Upvotes: 2

Related Questions