From 04a0615972f06972435a68b5ae428021a31f0d33 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 9 May 2016 14:20:04 -0700 Subject: [PATCH] default selenium to raising an error when there are unexpected alerts --- lib/capybara/selenium/driver.rb | 1 + lib/capybara/spec/session/reset_session_spec.rb | 7 +++++++ lib/capybara/spec/views/with_unload_alert.erb | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index b26945ad..b22f5cd8 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -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." diff --git a/lib/capybara/spec/session/reset_session_spec.rb b/lib/capybara/spec/session/reset_session_spec.rb index 01aaf67e..f2c14cc7 100644 --- a/lib/capybara/spec/session/reset_session_spec.rb +++ b/lib/capybara/spec/session/reset_session_spec.rb @@ -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 diff --git a/lib/capybara/spec/views/with_unload_alert.erb b/lib/capybara/spec/views/with_unload_alert.erb index 16def8da..4bcb4cd0 100644 --- a/lib/capybara/spec/views/with_unload_alert.erb +++ b/lib/capybara/spec/views/with_unload_alert.erb @@ -8,5 +8,7 @@
This triggers an alert on unload
+ + Go away - \ No newline at end of file +