问题
How can I get the current Example
out of a Ruby cucumber test in an After
hook?
I can get the title with the code below. My Scenario
has several Examples
with it. Can I access the current Example
being tested?
Feature file
Scenario Outline: Successful login with primary accounts
Given I start on the login page
When I log into Overview page with "<acct>"
Then I am on the Overview page
Examples:
| acct |
| account1 |
| account2 |
After hook
After do |scenario|
scenario.scenario_outline.title # will give me the title
How to I get the current Example
?
回答1:
Here is how I did it.
scenario_title = scenario.respond_to?(:scenario_outline) ? scenario.scenario_outline.title : ''
scenario_title_example = scenario.respond_to?(:name) ? scenario.name : ''
scenario_full_title = scenario_title + scenario_title_example
来源:https://stackoverflow.com/questions/31864767/accessing-the-scenario-title-and-example-in-a-cucumber-after-hook