From 4027b0d93ba0e8c26f97a1ae515fa3f2dc6918a1 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Mon, 12 Feb 2018 10:07:06 -0800 Subject: [PATCH] Remove no longer necessary modal injection --- History.md | 7 ++++ lib/capybara/selenium/driver.rb | 50 ++++++----------------- lib/capybara/spec/views/initial_alert.erb | 10 +++++ spec/shared_selenium_session.rb | 10 ++--- 4 files changed, 34 insertions(+), 43 deletions(-) create mode 100644 lib/capybara/spec/views/initial_alert.erb diff --git a/History.md b/History.md index cd392498..5429ddbb 100644 --- a/History.md +++ b/History.md @@ -15,6 +15,13 @@ Release date: unreleased * `Capybara.exact_options` no longer exists. Just use `exact:true` on relevant actions/finders if necessary. +#Version 2.18.0 +Release date: unreleased + +### Removed + +* Headless chrome modal JS injection that is no longer needed for Chrome 64+/chromedriver 2.35+ + # Version 2.17.0 Release date: 2018-01-02 diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index bf3ba334..732fc728 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -215,36 +215,22 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base end def accept_modal(_type, **options) - if headless_chrome? - raise ArgumentError, "Block that triggers the system modal is missing" unless block_given? - insert_modal_handlers(true, options[:with]) - yield - find_headless_modal(options) - else - yield if block_given? - modal = find_modal(options) + yield if block_given? + modal = find_modal(options) - modal.send_keys options[:with] if options[:with] + modal.send_keys options[:with] if options[:with] - message = modal.text - modal.accept - message - end + message = modal.text + modal.accept + message end def dismiss_modal(_type, **options) - if headless_chrome? - raise ArgumentError, "Block that triggers the system modal is missing" unless block_given? - insert_modal_handlers(false, options[:with]) - yield - find_headless_modal(options) - else - yield if block_given? - modal = find_modal(options) - message = modal.text - modal.dismiss - message - end + yield if block_given? + modal = find_modal(options) + message = modal.text + modal.dismiss + message end def quit @@ -292,20 +278,8 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base browser_name == "chrome" end - # @api private - def headless_chrome? - if chrome? - caps = @processed_options[:desired_capabilities] - chrome_options = caps[:chrome_options] || caps[:chromeOptions] || {} - args = chrome_options['args'] || chrome_options[:args] || [] - return args.include?("--headless") || args.include?("headless") - end - return false - end + private -private - - # @api private def browser_name options[:browser].to_s end diff --git a/lib/capybara/spec/views/initial_alert.erb b/lib/capybara/spec/views/initial_alert.erb new file mode 100644 index 00000000..c0294d79 --- /dev/null +++ b/lib/capybara/spec/views/initial_alert.erb @@ -0,0 +1,10 @@ + + +
+ Initial alert page +
+ + + diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index f137f102..8b7e687c 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -57,16 +57,16 @@ RSpec.shared_examples "Capybara::Session" do |session, mode| describe "#accept_alert" do it "supports a blockless mode" do @session.visit('/with_js') - skip "Headless Chrome doesn't support blockless modal methods" if @session.driver.send(:headless_chrome?) @session.click_link('Open alert') @session.accept_alert expect{@session.driver.browser.switch_to.alert}.to raise_error(@session.driver.send(:modal_error)) end - it "raises if block is missing" do - @session.visit('/with_js') - skip "Only Headless Chrome requires the block due to system modal JS injection" unless @session.driver.send(:headless_chrome?) - expect { @session.accept_alert }.to raise_error(ArgumentError) + it "can be called before visiting" do + @session.accept_alert "Initial alert" do + @session.visit('/initial_alert') + end + expect(@session).to have_text('Initial alert page') end end