访问场景标题和示例在黄瓜后挂钩 [英] Accessing the Scenario Title and Example in a Cucumber After hook

查看:188
本文介绍了访问场景标题和示例在黄瓜后挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在之后的钩子中获取当前示例 >

我可以使用下面的代码获得标题。我的场景有几个示例。我可以访问当前示例正在测试吗?



功能文件

  :使用主帐户成功登录
假定我从登录页面开始
当我使用< acct>登录到概述页面时
然后我在概述页面

示例:
| acct |
| account1 |
| account2 |

挂钩后

  After | scenario | 
scenario.scenario_outline.title#将给我标题

如何获取当前示例?

解决方案

这是我做的。

  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


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?

解决方案

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

这篇关于访问场景标题和示例在黄瓜后挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆