如何确定我刚刚在 Cucumber 的 AfterStep 挂钩中执行了哪个步骤? [英] How can I figure out which step I've just executed in Cucumber's AfterStep hook?

查看:11
本文介绍了如何确定我刚刚在 Cucumber 的 AfterStep 挂钩中执行了哪个步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Cucumber 编写一个在 AfterStep 回调上执行的方法.

I'm writing a method to be executed on the AfterStep callback for Cucumber.

https://github.com/cucumber/cucumber/wiki/Hooks#步钩

如何确定在调用此钩子之前执行了哪个步骤?

How can I figure out which step was executed before this hook was called?

推荐答案

AfterStep 钩子只接收场景作为参数.

The AfterStep hook only receives the scenario as parameter.

你可以做的,就是计算步数,然后得到当前的步数:

What you can do, is count the steps, and then get the current one:

AfterStep do |scenario|
  @step ||= 0
  p scenario.steps[@step].name
  @step += 1
end

这将依次打印每个参数的名称

This will print, in turn, the names of each parameter

这篇关于如何确定我刚刚在 Cucumber 的 AfterStep 挂钩中执行了哪个步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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