我知道这是一个不必要的用例,也是一个非常糟糕的做法。但是,我仍然很好奇,看看是否有可能从“ After”挂钩中手动设置场景的状态。我正在将Cucumber 2.4.0和Ruby一起用于我的测试自动化。
经过一番研究,我发现可以在“ After”挂钩中手动设置场景的状态。参见下面的例子
After do |scenario|
duration = scenario.instance_variable_get(:@result).instance_variable_get(:@duration)
if scenario.failed?
# Manually set to passed
passed = Cucumber::Core::Test::Result::Passed.new(duration)
scenario.instance_variable_set(:@result, passed)
elsif scenario.passed?
# Manually set to failed
exception = StandardError.new("message")
failed = Cucumber::Core::Test::Result::Failed.new(duration, exception)
scenario.instance_variable_set(:@result, failed)
end
随时添加建议/评论
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句