You can get the after hook to fail using your normal assertions. Have not done much with Capybara/rspec exceptions, but I think you can do:
page.should have_selector?(:dialog_message, 1, :text => 'Error')
However, if you do this or do the scenario.fail!(), you will still not logout. You need to wrap it in a begin-ensure block.
Try this:
After do |scenario|
begin
page.should have_selector?(:dialog_message, 1, :text => 'Error')
ensure
logout
end
end
Update
If you do not want to call the standard assertions and directly fail the scenario, you can do the following - you need to use fail
instead of fail!
:
After() do |scenario|
begin
#Checking for Error popups
if page.has_selector?(:dialog_message, 1, :text => 'Error')
fail(ArgumentError.new('Unexpected Error dialog!'))
#Or you can just do fail('Unexpected Error dialog') if you do not care about the type.
end
ensure
logout
end
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…