default selenium to raising an error when there are unexpected alerts

This commit is contained in:
Thomas Walpole 2016-05-09 14:20:04 -07:00
parent 55c2ec3542
commit 04a0615972
3 changed files with 11 additions and 1 deletions

View File

@ -27,6 +27,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
def initialize(app, options={})
begin
require 'selenium-webdriver'
Selenium::WebDriver::Remote::Capabilities::DEFAULTS["unexpectedAlertBehaviour"] = "ignore"
rescue LoadError => e
if e.message =~ /selenium-webdriver/
raise LoadError, "Capybara's selenium driver is unable to load `selenium-webdriver`, please install the gem and add `gem 'selenium-webdriver'` to your Gemfile if you are using bundler."

View File

@ -46,6 +46,13 @@ Capybara::SpecHelper.spec '#reset_session!' do
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
end
it "handles already open modals" do
@session.visit('/with_unload_alert')
@session.click_link('Go away')
expect { @session.reset_session! }.not_to raise_error
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
end
it "raises any standard errors caught inside the server", :requires => [:server] do
quietly { @session.visit("/error") }
expect do

View File

@ -8,5 +8,7 @@
</head>
<body>
<div>This triggers an alert on unload</div>
<a href="/">Go away</a>
</body>
</html>
</html>