Accessing the Scenario Title and Example in a Cucumber After hook

拟墨画扇 提交于 2019-12-06 15:06:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!