1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Remove no longer necessary modal injection

This commit is contained in:
Thomas Walpole 2018-02-12 10:07:06 -08:00
parent 973a1f2605
commit 4027b0d93b
4 changed files with 34 additions and 43 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<body>
<div>
Initial alert page
</div>
<script>
window.alert("Initial alert");
</script>
</body>
</html>

View file

@ -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