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

cleanup marionette specific node behavior

This commit is contained in:
Thomas Walpole 2017-05-08 15:12:33 -07:00
parent 1467a80ae5
commit 0561020670
7 changed files with 42 additions and 29 deletions

View file

@ -22,6 +22,9 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
@processed_options = options.reject { |key,_val| SPECIAL_OPTIONS.include?(key) }
@browser = Selenium::WebDriver.for(options[:browser], @processed_options)
@w3c = ((defined?(Selenium::WebDriver::Remote::W3CCapabilities) && @browser.capabilities.is_a?(Selenium::WebDriver::Remote::W3CCapabilities)) ||
(defined?(Selenium::WebDriver::Remote::W3C::Capabilities) && @browser.capabilities.is_a?(Selenium::WebDriver::Remote::W3C::Capabilities)))
main = Process.pid
at_exit do
# Store the exit status of the test run since it goes away after calling the at_exit proc...
@ -288,6 +291,37 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
end
# @api private
def marionette?
firefox? && browser && @w3c
end
# @api private
def firefox?
browser_name == "firefox"
end
# @api private
def chrome?
browser_name == "chrome"
end
# @api private
def headless_chrome?
chrome? && ((@processed_options[:desired_capabilities][:chrome_options] || {})['args'] || []).include?("headless")
end
# @deprecated This method is being removed
def browser_initialized?
super && !@browser.nil?
end
private
# @api private
def browser_name
options[:browser].to_s
end
def find_window(locator)
handles = browser.window_handles
return locator if handles.include? locator
@ -305,18 +339,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
raise Capybara::ElementNotFound, "Could not find a window identified by #{locator}"
end
#@api private
def marionette?
(options[:browser].to_s == "firefox") && browser.capabilities.is_a?(Selenium::WebDriver::Remote::W3CCapabilities)
end
# @deprecated This method is being removed
def browser_initialized?
super && !@browser.nil?
end
private
def insert_modal_handlers(accept, response_text, expected_text=nil)
script = <<-JS
if (typeof window.capybara === 'undefined') {
@ -435,16 +457,4 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
arg
end
end
def firefox?
options[:browser].to_s == "firefox"
end
def chrome?
options[:browser].to_s == "chrome"
end
def headless_chrome?
chrome? && ((@processed_options[:desired_capabilities][:chrome_options] || {})['args'] || []).include?("headless")
end
end

View file

@ -47,7 +47,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
click if value ^ native.attribute('checked').to_s.eql?("true")
elsif tag_name == 'input' and type == 'file'
path_names = value.to_s.empty? ? [] : value
if driver.options[:browser].to_s == "chrome"
if driver.chrome?
native.send_keys(Array(path_names).join("\n"))
else
native.send_keys(*path_names)
@ -88,8 +88,8 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
JS
driver.execute_script script, self
if (driver.options[:browser].to_s == "chrome") ||
(driver.options[:browser].to_s == "firefox" && !driver.marionette?)
if (driver.chrome?) ||
(driver.firefox? && !driver.marionette?)
# chromedriver raises a can't focus element for child elements if we use native.send_keys
# we've already focused it so just use action api
driver.browser.action.send_keys(value.to_s).perform

View file

@ -117,7 +117,7 @@ module Capybara
end
def marionette?(session)
session.driver.respond_to?(:marionette?) && session.driver.marionette?
session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
end
def rspec2?

View file

@ -36,6 +36,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && ENV['CAPYBARA_CHROME_HEADLESS']
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with chrome" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
context "storage" do

View file

@ -36,6 +36,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with legacy firefox" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_firefox
include_examples Capybara::RSpecMatchers, TestSessions::Selenium, :selenium_firefox

View file

@ -36,6 +36,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with firefox" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::SeleniumMarionette, :selenium_marionette
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumMarionette, :selenium_marionette
end

View file

@ -101,7 +101,7 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
context "#fill_in with { clear: Array } fill_options" do
it 'should pass the array through to the element' do
pending "selenium-webdriver/geckodriver doesn't support complex sets of characters" if @session.driver.marionette?
pending "selenium-webdriver/geckodriver doesn't support complex sets of characters" if marionette?(@session)
#this is mainly for use with [[:control, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
@session.visit('/form')
@session.fill_in('form_first_name', with: 'Harry',