【问题标题】:Ruby cucumber scenario hook execution orderruby 黄瓜场景钩子执行顺序
【发布时间】:2014-08-04 18:08:58
【问题描述】:

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

我的钩子

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

【问题讨论】:

    标签: ruby cucumber hook scenarios


    【解决方案1】:

    After hooks run in the opposite order to that in which they appear in your support/*.rb files. 钩子是否特定于标签不会影响它的运行顺序。要使标记的钩子在未标记的钩子之前运行,请将标记的钩子放在未标记的钩子之后。

    【讨论】:

    【解决方案2】:

    before 钩子按照声明它们的顺序运行。 https://docs.cucumber.io/cucumber/api/#hooks

    【讨论】:

      猜你喜欢
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多