【问题标题】:Cucumber : How to print/get all the executed scenario count with status like "Execution Report - Total: 5, passed: 4, failed: 1"Cucumber:如何打印/获取所有已执行的场景计数,状态为“执行报告 - 总计:5,通过:4,失败:1”
【发布时间】:2026-02-01 19:30:02
【问题描述】:

我正在计算After do中的场景

After do |scenario|
    if scenario.status.to_s=="passed"
      $passed=$passed+1
    elsif scenario.status.to_s=="failed"
      $failed=$failed+1
    end
    $scenario_count=$scenario_count+1
  end
  @browser.close
end 

在出口处就像

at_exit do |scenario|

 puts  "Execution Report - Total: #{$scenario_count}, passed: #{$passed}, failed: #{$failed}"

end

但我得到了

执行报告 - 总计:1,通过:1,失败:

反正有没有得到所有已执行场景的计数,因为我需要在电子邮件中使用它。它只返回最后一个场景的结果。

【问题讨论】:

    标签: ruby cucumber watir


    【解决方案1】:

    它适用于从方法中初始化变量值

    $passed=0
    $failed=0
    $scenario_count=0
    
    After do |scenario|
        if scenario.status.to_s=="passed"
          $passed=$passed+1
        elsif scenario.status.to_s=="failed"
          $failed=$failed+1
        end
        $scenario_count=$scenario_count+1
      end
      @browser.close
    end 
    

    【讨论】:

    • 确保你在Before hook中添加了它们,这样会更干净。
    最近更新 更多