我有一个 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/