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:
parent
1467a80ae5
commit
0561020670
7 changed files with 42 additions and 29 deletions
|
@ -22,6 +22,9 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
@processed_options = options.reject { |key,_val| SPECIAL_OPTIONS.include?(key) }
|
@processed_options = options.reject { |key,_val| SPECIAL_OPTIONS.include?(key) }
|
||||||
@browser = Selenium::WebDriver.for(options[:browser], @processed_options)
|
@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
|
main = Process.pid
|
||||||
at_exit do
|
at_exit do
|
||||||
# Store the exit status of the test run since it goes away after calling the at_exit proc...
|
# 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
|
end
|
||||||
|
|
||||||
# @api private
|
# @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)
|
def find_window(locator)
|
||||||
handles = browser.window_handles
|
handles = browser.window_handles
|
||||||
return locator if handles.include? locator
|
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}"
|
raise Capybara::ElementNotFound, "Could not find a window identified by #{locator}"
|
||||||
end
|
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)
|
def insert_modal_handlers(accept, response_text, expected_text=nil)
|
||||||
script = <<-JS
|
script = <<-JS
|
||||||
if (typeof window.capybara === 'undefined') {
|
if (typeof window.capybara === 'undefined') {
|
||||||
|
@ -435,16 +457,4 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
arg
|
arg
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
click if value ^ native.attribute('checked').to_s.eql?("true")
|
click if value ^ native.attribute('checked').to_s.eql?("true")
|
||||||
elsif tag_name == 'input' and type == 'file'
|
elsif tag_name == 'input' and type == 'file'
|
||||||
path_names = value.to_s.empty? ? [] : value
|
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"))
|
native.send_keys(Array(path_names).join("\n"))
|
||||||
else
|
else
|
||||||
native.send_keys(*path_names)
|
native.send_keys(*path_names)
|
||||||
|
@ -88,8 +88,8 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
||||||
JS
|
JS
|
||||||
driver.execute_script script, self
|
driver.execute_script script, self
|
||||||
|
|
||||||
if (driver.options[:browser].to_s == "chrome") ||
|
if (driver.chrome?) ||
|
||||||
(driver.options[:browser].to_s == "firefox" && !driver.marionette?)
|
(driver.firefox? && !driver.marionette?)
|
||||||
# chromedriver raises a can't focus element for child elements if we use native.send_keys
|
# 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
|
# we've already focused it so just use action api
|
||||||
driver.browser.action.send_keys(value.to_s).perform
|
driver.browser.action.send_keys(value.to_s).perform
|
||||||
|
|
|
@ -117,7 +117,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def marionette?(session)
|
def marionette?(session)
|
||||||
session.driver.respond_to?(:marionette?) && session.driver.marionette?
|
session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rspec2?
|
def rspec2?
|
||||||
|
|
|
@ -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
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: skipped_tests
|
||||||
|
|
||||||
RSpec.describe "Capybara::Session with chrome" do
|
RSpec.describe "Capybara::Session with chrome" do
|
||||||
|
include Capybara::SpecHelper
|
||||||
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
|
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
|
||||||
|
|
||||||
context "storage" do
|
context "storage" do
|
||||||
|
|
|
@ -36,6 +36,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
|
||||||
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
|
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
|
||||||
|
|
||||||
RSpec.describe "Capybara::Session with legacy firefox" do
|
RSpec.describe "Capybara::Session with legacy firefox" do
|
||||||
|
include Capybara::SpecHelper
|
||||||
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_firefox
|
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_firefox
|
||||||
include_examples Capybara::RSpecMatchers, TestSessions::Selenium, :selenium_firefox
|
include_examples Capybara::RSpecMatchers, TestSessions::Selenium, :selenium_firefox
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
|
||||||
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
|
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
|
||||||
|
|
||||||
RSpec.describe "Capybara::Session with firefox" do
|
RSpec.describe "Capybara::Session with firefox" do
|
||||||
|
include Capybara::SpecHelper
|
||||||
include_examples "Capybara::Session", TestSessions::SeleniumMarionette, :selenium_marionette
|
include_examples "Capybara::Session", TestSessions::SeleniumMarionette, :selenium_marionette
|
||||||
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumMarionette, :selenium_marionette
|
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumMarionette, :selenium_marionette
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,7 +101,7 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
||||||
|
|
||||||
context "#fill_in with { clear: Array } fill_options" do
|
context "#fill_in with { clear: Array } fill_options" do
|
||||||
it 'should pass the array through to the element' 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
|
#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.visit('/form')
|
||||||
@session.fill_in('form_first_name', with: 'Harry',
|
@session.fill_in('form_first_name', with: 'Harry',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue