在 Cucumber After hook 中访问场景标题和示例示例、场景、标题、Cucumber

2023-09-08 00:36:12 作者:/.赱私娚孒o.

如何从 After 挂钩中的 Ruby cucumber 测试中获取当前的 Example?

How can I get the current Example out of a Ruby cucumber test in an After hook?

我可以通过下面的代码获得标题.我的 Scenario 有几个 Examples .我可以访问当前正在测试的 Example 吗?

I can get the title with the code below. My Scenario has several Examples with it. Can I access the current Example being tested?

功能文件

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 do |scenario|
  scenario.scenario_outline.title   # will give me the title

如何获取当前的Example?

推荐答案

我是这样做的.

  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
 
精彩推荐
图片推荐