Accessing the Scenario Title and Example in a Cucu

2019-04-17 05:30发布

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条回答
干净又极端
2楼-- · 2019-04-17 06:16

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
查看更多
登录 后发表回答