gpt4 book ai didi

ruby - 获取当前步骤表单场景大纲

转载 作者:太空宇宙 更新时间:2023-11-03 17:23:28 25 4
gpt4 key购买 nike

我正在尝试访问场景大纲测试中的当前步骤名称。下面的代码适用于常规场景,但不适用于场景大纲。

AfterStep do |scenario|
#step = scenario.steps.find { |s| s.status == :skipped }
#puts step.keyword + step.name

case scenario
when Cucumber::Ast::Scenario
step = scenario.steps.find { |s| s.status == :skipped }
puts step.keyword + ' ' + step.name
#Works correctly

when Cucumber::Ast::OutlineTable::ExampleRow
# **!!!!Exception below!!!**
step = scenario.scenario_outline.steps.find { |s| s.status == :skipped }
puts step.keyword + ' ' + step.name

end
end

异常(exception):

NoMethodError: undefined method `steps' for #<Cucumber::Ast::OutlineTable::ExampleRow:0x007fe0b8214bc0>

有人知道怎么解决吗?或者这是否可能?

最佳答案

尝试以下方式:

Before do |scenario|
...
# step counter
@step_count = 0
end

AfterStep do |step|
current_feature = if scenario.respond_to?('scenario_outline')
# execute the following code only for scenarios outline (starting from the second example)
scenario.scenario_outline.feature
else
# execute the following code only for a scenario and a scenario outline (the first example only)
scenario.feature
end


# call method 'steps' and select the current step
# we use .send because the method 'steps' is private for scenario outline
step_title = current_feature.feature_elements[0].send(:steps).to_a[@step_count].name

p step_title

# increase step counter
@step_count += 1
end

它必须适用于“场景”和“场景大纲”

关于ruby - 获取当前步骤表单场景大纲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22482559/

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