ruby 是否可以输出每个场景运行的场景百分比?

zujrkrfu  于 5个月前  发布在  Ruby
关注(0)|答案(1)|浏览(76)

在Ruby上的Cucumber中,当运行大功能时,我想看看我已经走了多远;一个有用的信息是类似于“100个场景中的20个”或“完成了30%的场景”,与场景标题一起打印。
这将是很容易实现自己在一个钩子,如果有一种方法来获得上述信息(即当前场景在当前功能文件中的位置;加上同一文件中的场景总数)。这可能吗?我知道有cucumber-ruby API文档,但我不清楚如何从cucumber核心实现之外(即从“用户区域”)访问这些东西。

lzfw57am

lzfw57am1#

是的,可以在Cucumber with Ruby中实现一个功能,输出场景运行的百分比,以及每个场景的沿着。为了实现这一点,您可以使用Cucumber的钩子和Runner类来跟踪场景的进度。

# Define global variables to track progress
$total_scenarios = 0
$current_scenario = 0

BeforeAll do
  # Calculate total number of scenarios
  # This might vary depending on how your test suite is structured
  $total_scenarios = Cucumber::Core::Test::Runner.scenarios.count
end

Before do |scenario|
  # Increment the current scenario count
  $current_scenario += 1

  # Calculate the progress
  progress_percent = ($current_scenario.to_f / $total_scenarios.to_f * 100).round(2)

  # Output the progress
  puts "Scenario #{$current_scenario} of #{$total_scenarios} (#{progress_percent}%)"
  puts "Running Scenario: #{scenario.name}"
end

AfterAll do
  # Any finalization if needed
end

字符串

相关问题