gpt4 book ai didi

ruby - 我怎样才能确定我刚刚在 Cucumber 的 AfterStep Hook 中执行了哪一步?

转载 作者:数据小太阳 更新时间:2023-10-29 08:27:29 25 4
gpt4 key购买 nike

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

https://github.com/cucumber/cucumber/wiki/Hooks#step-hooks

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

最佳答案

使用gem cucumber 2.1.0和scenario outlines,“Afterstep”中的scenario对象只是测试结果状态,不包含步骤名称。我必须使用包含测试列表的“之前”(在第一步之前调用)。

require 'logger'

$logger = Logger.new(STDOUT)

Before do |scenario|

@count = 0
@tests = Array.new

scenario.test_steps.each{|r|
if( r.name != "AfterStep hook")
@tests << r
end
}
end

AfterStep do |scenario| # run after each step

$logger.info(@tests[@count].name.green)
@count += 1;

end

记录器是必需的,因为“puts”仅在场景大纲结束时显示。

关于ruby - 我怎样才能确定我刚刚在 Cucumber 的 AfterStep Hook 中执行了哪一步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20912864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com