Ruby cucumber 场景钩子(Hook)执行顺序

标签 ruby cucumber hook scenarios

我有一个 After Hook ,它在场景本身的 Hook 之前执行。我想颠倒那些钩子(Hook)运行的顺序。目前,“After do” Hook 在“After('@66075')”之前运行,并且 66075 中的清理必须首先运行。

我的钩子(Hook)

After('@66075') do
  begin
    #cleanup
  rescue => detail
    puts detail.message
    puts detail.backtrace.join("\n")
  end
end

After do |scenario|
  begin
    if scenario.failed?
      #do stuff
    end
  rescue
    puts "process for failing scenarios failed"
  end
  begin
    @browser.link(:text, 'Logout').click
    sleep(0.5)
    @browser.alert.ok if @browser.alert.exists?
  rescue => detail
    puts detail.message
    puts detail.backtrace.join("\n")
    puts "logout and close windows failed"
  end
end

和我的场景:

 @66075 
  Scenario: my Scenario
    Given A
    When B
    Then C

最佳答案

After hooks run in the opposite order to that in which they appear in your support/*.rb files.一个钩子(Hook)是否特定于一个标签并不影响它运行的顺序。要让你的标记钩子(Hook)在你的非标记钩子(Hook)之前运行,把你的标记钩子(Hook)放在你的非标记钩子(Hook)之后。

关于Ruby cucumber 场景钩子(Hook)执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25124903/

相关文章:

ruby-on-rails - 安装 Rack 时出错

ruby - 你如何将 cucumber 场景标记为待处理

ember.js - Ember : Router pre and post hooks connectOutlets

git - 如何在当前 HEAD 和推送中的最新文件之间的预接收 Hook 中获取文件的 git diff?

ruby - 在 docker 中运行一个简单的 ruby​​ 文件并将输出重定向到一个文件

Ruby 文件在最后一个空行之后无法读取内容\n

javascript - 在没有测试数据的情况下使cucumber测试成功

ruby-on-rails - 如何在 cucumber / capybara 步骤定义中进行xpath正则表达式搜索(Rails 3)?

c++ - 使用 C++ 模板包装第 3 方 C 代码

ruby-on-rails - ActiveRecord 列表自定义范围